1 #! /usr/bin/env python3
2 """Run through the bookmarks database and set names to titles
5 This file is a part of Bookmarks database and Internet robot.
8 from __future__ import print_function
12 __author__ = "Oleg Broytman <phd@phdru.name>"
13 __copyright__ = "Copyright (C) 2003-2023 PhiloSoft Design"
14 __license__ = "GNU GPL"
18 from getopt import getopt
19 optlist, args = getopt(sys.argv[1:], "s")
23 for _opt, _arg in optlist:
32 print("Broytman set-title-list, Copyright (C)"
33 " 2003-2023 PhiloSoft Design")
36 sys.stderr.write("Usage: set-title-list [-s] title_list_file\n")
39 # Read the external file with titles and build a mapping (URL => title)
45 title_list_file = open(args[0], 'rt', encoding='utf-8')
46 for line in title_list_file:
47 line = line[:-1] # strip trailing newline
54 elif line: # the third line in every 3 lines must be empty
56 "line is not empty for URL `%s', title `%s': line `%s'"
60 else: # We've got 3 lines - add new entry to the mapping
61 if URL in titles_dict:
62 if title != titles_dict[URL]:
64 "titles are not identical for URL `%s': `%s' != `%s'"
65 % (URL, title, titles_dict[URL])
69 titles_dict[URL] = title
75 title_list_file.close()
77 from storage import storage
81 sys.stdout.write("Loading %s: " % storage.filename)
84 root_folder = storage.load()
85 from bkmk_objects import make_linear, break_tree
86 make_linear(root_folder)
87 objects = len(root_folder.linear)
92 # Run through the list of objects and check URLs/titles
94 for object_no in range(objects):
95 object = root_folder.linear[object_no]
99 if URL in titles_dict:
100 name = titles_dict[URL]
101 if object.name != name:
105 if changed and report_stats:
106 sys.stdout.write("Saving %s: " % storage.filename)
109 if not changed and report_stats:
110 sys.stdout.write("No need to save data\n")
114 break_tree(root_folder.linear)
115 storage.store(root_folder)
117 if changed and report_stats:
119 print(objects, "objects passed")
120 print(changed, "objects changed")
123 if __name__ == '__main__':