]> git.phdru.name Git - bookmarks_db.git/blob - check_title.py
Underline IDNA encoding.
[bookmarks_db.git] / check_title.py
1 #! /usr/bin/env python
2 """Check and show URLs in the bookmarks database where name != real title
3
4 This file is a part of Bookmarks database and Internet robot.
5 """
6
7 __version__ = "$Revision$"[11:-2]
8 __revision__ = "$Id$"[5:-2]
9 __date__ = "$Date$"[7:-2]
10 __author__ = "Oleg Broytman <phd@phdru.name>"
11 __copyright__ = "Copyright (C) 2002-2011 PhiloSoft Design"
12 __license__ = "GNU GPL"
13
14 import sys
15 from bkmk_objects import make_linear, quote_title, unquote_title
16
17
18 def run():
19    from getopt import getopt
20    optlist, args = getopt(sys.argv[1:], "s")
21
22    report_stats = 1
23
24    for _opt, _arg in optlist:
25       if _opt == '-s':
26          report_stats = 0
27    try:
28       del _opt, _arg
29    except NameError:
30       pass
31
32    if report_stats:
33       print "Broytman check_title, Copyright (C) 2002-2010 PhiloSoft Design"
34
35    if args:
36       sys.stderr.write("check_title: too many arguments\n")
37       sys.stderr.write("Usage: check_title [-s]\n")
38       sys.exit(1)
39
40    from storage import storage
41    storage = storage()
42
43    if report_stats:
44       sys.stdout.write("Loading %s: " % storage.filename)
45       sys.stdout.flush()
46
47    root_folder = storage.load()
48    make_linear(root_folder)
49    objects = len(root_folder.linear)
50
51    if report_stats:
52       print "Ok"
53
54
55    for object_no in range(objects):
56       object = root_folder.linear[object_no]
57
58       if object.isBookmark:
59          if hasattr(object, "moved") or hasattr(object, "error") \
60                or object.href.startswith('place:'): # Firefox SmartBookmarks
61             continue
62
63          if hasattr(object, "real_title") and (object.real_title is not None):
64             unquoted_title = unquote_title(quote_title(object.real_title))
65             unquoted_name = unquote_title(object.name)
66             if unquoted_name <> unquoted_title:
67                print object.href
68                print unquoted_name
69                print unquoted_title
70                print
71          else:
72             print object.href
73             print object.name
74             print "NO REAL TITLE!!!"
75             print
76
77
78    if report_stats:
79       print objects, "objects passed"
80
81
82 if __name__ == '__main__':
83    run()