]> git.phdru.name Git - bookmarks_db.git/blob - check_title.py
870d968f785e8dc55429e269c4ee5b6108035741
[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-2023 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-2023 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     for object_no in range(objects):
54         object = root_folder.linear[object_no]
55
56         if object.isBookmark:
57             if hasattr(object, "moved") or hasattr(object, "error") \
58                   or object.href.startswith('place:'):  # Firefox SmartBookmarks
59                 continue
60
61             if hasattr(object, "real_title") and (object.real_title is not None):
62                 unquoted_title = unquote_title(quote_title(object.real_title))
63                 unquoted_name = unquote_title(object.name)
64                 if unquoted_name != unquoted_title:
65                     print(object.href)
66                     print(unquoted_name)
67                     print(unquoted_title)
68                     print()
69             else:
70                 print(object.href)
71                 print(object.name)
72                 print("NO REAL TITLE!!!")
73                 print()
74
75     if report_stats:
76         print(objects, "objects passed")
77
78
79 if __name__ == '__main__':
80     run()