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