1 #! /usr/bin/env python3
2 """Check and show URLs in the bookmarks database that have redirects
4 This file is a part of Bookmarks database and Internet robot.
7 from __future__ import print_function
9 from bkmk_objects import make_linear
12 __author__ = "Oleg Broytman <phd@phdru.name>"
13 __copyright__ = "Copyright (C) 2023 PhiloSoft Design"
14 __license__ = "GNU GPL"
17 def report_redirect(href, moved):
19 log_file.write("%s\n%s\n\n" % (href, moved))
21 print("URL: %s\nMoved to: %s\n" % (href, moved))
25 from getopt import getopt
26 optlist, args = getopt(sys.argv[1:], "sl:")
32 for _opt, _arg in optlist:
43 print("Broytman check_redirects, Copyright (C) 2023 PhiloSoft Design")
46 sys.stderr.write("check_redirects: too many arguments\n")
47 sys.stderr.write("Usage: check_redirects [-s] [-l logfile]\n")
51 log_file = open(log_filename, 'wt', encoding='utf-8')
53 from storage import storage
57 sys.stdout.write("Loading %s: " % storage.filename)
60 root_folder = storage.load()
61 make_linear(root_folder)
62 objects = len(root_folder.linear)
68 for object_no in range(objects):
69 object = root_folder.linear[object_no]
72 if hasattr(object, "error") or \
73 object.href.startswith('place:'): # Firefox SmartBookmarks
76 if hasattr(object, "moved"):
77 report_redirect(object.href, object.moved)
82 print(objects, "objects passed")
83 print(redirects, "redirects")
86 if __name__ == '__main__':