]> git.phdru.name Git - bookmarks_db.git/blob - check_title.py
Moved parse_html.py and its submodules to a separate parse_html module.
[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-2010 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-2010 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                or object.href.startswith('place:'): # Firefox SmartBookmarks
55             continue
56
57          if hasattr(object, "real_title") and (object.real_title is not None):
58             unquoted_title = unquote_title(quote_title(object.real_title))
59             unquoted_name = unquote_title(object.name)
60             if unquoted_name <> unquoted_title:
61                print object.href
62                print unquoted_name
63                print unquoted_title
64                print
65          else:
66             print object.href
67             print object.name
68             print "NO REAL TITLE!!!"
69             print
70
71
72    if report_stats:
73       print objects, "objects passed"
74
75
76 if __name__ == '__main__':
77    run()