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