]> git.phdru.name Git - bookmarks_db.git/blob - check_title.py
Add a few TODO items
[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 __author__ = "Oleg Broytman <phd@phdru.name>"
8 __copyright__ = "Copyright (C) 2002-2012 PhiloSoft Design"
9 __license__ = "GNU GPL"
10
11 import sys
12 from bkmk_objects import make_linear, quote_title, unquote_title
13
14
15 def run():
16    from getopt import getopt
17    optlist, args = getopt(sys.argv[1:], "s")
18
19    report_stats = 1
20
21    for _opt, _arg in optlist:
22       if _opt == '-s':
23          report_stats = 0
24    try:
25       del _opt, _arg
26    except NameError:
27       pass
28
29    if report_stats:
30       print "Broytman check_title, Copyright (C) 2002-2010 PhiloSoft Design"
31
32    if args:
33       sys.stderr.write("check_title: too many arguments\n")
34       sys.stderr.write("Usage: check_title [-s]\n")
35       sys.exit(1)
36
37    from storage import storage
38    storage = storage()
39
40    if report_stats:
41       sys.stdout.write("Loading %s: " % storage.filename)
42       sys.stdout.flush()
43
44    root_folder = storage.load()
45    make_linear(root_folder)
46    objects = len(root_folder.linear)
47
48    if report_stats:
49       print "Ok"
50
51
52    for object_no in range(objects):
53       object = root_folder.linear[object_no]
54
55       if object.isBookmark:
56          if hasattr(object, "moved") or hasattr(object, "error") \
57                or object.href.startswith('place:'): # Firefox SmartBookmarks
58             continue
59
60          if hasattr(object, "real_title") and (object.real_title is not None):
61             unquoted_title = unquote_title(quote_title(object.real_title))
62             unquoted_name = unquote_title(object.name)
63             if unquoted_name <> unquoted_title:
64                print object.href
65                print unquoted_name
66                print unquoted_title
67                print
68          else:
69             print object.href
70             print object.name
71             print "NO REAL TITLE!!!"
72             print
73
74
75    if report_stats:
76       print objects, "objects passed"
77
78
79 if __name__ == '__main__':
80    run()