1 #! /usr/bin/env python3
2 """Robot interface - check URLs from bookmarks database
4 This file is a part of Bookmarks database and Internet robot.
7 from __future__ import print_function
11 __author__ = "Oleg Broytman <phd@phdru.name>"
12 __copyright__ = "Copyright (C) 2000-2023 PhiloSoft Design"
13 __license__ = "GNU GPL"
17 from getopt import getopt
18 optlist, args = getopt(sys.argv[1:], "ise")
24 for _opt, _arg in optlist:
37 print("Broytman check_urls, Copyright (C) 1997-2023 PhiloSoft Design")
40 sys.stderr.write("check_urls: too many arguments\n")
41 sys.stderr.write("Usage: check_urls [-ise]\n")
45 show_pbar = sys.stderr.isatty()
49 from m_lib.pbar.tty_pbar import ttyProgressBar
53 from m_lib.flog import makelog, openlog
55 log = openlog("check.log")
56 log("chk_urls restarted for errors")
58 print("chk_urls restarted for errors")
60 log = makelog("check.log")
61 log("check_urls started")
63 print(" check_urls: normal start")
64 log.outfile.reconfigure(encoding='utf-8')
66 from storage import storage
69 from robots import robot
73 sys.stdout.write("Loading %s: " % storage.filename)
76 root_folder = storage.load()
77 from bkmk_objects import make_linear, break_tree
78 make_linear(root_folder)
79 objects = len(root_folder.linear)
86 s = "Rechecking errors: "
93 pbar = ttyProgressBar(0, objects)
102 for object_no in range(objects):
104 pbar.display(object_no+1)
106 object = root_folder.linear[object_no]
107 object_count = object_count + 1
109 if object.isBookmark:
111 if (href.startswith('place:') # Firefox SmartBookmarks
112 or '%s' in href): # Bookmark with keyword
113 log("Skipped %s" % href)
117 if hasattr(object, "error"):
118 delattr(object, "error")
123 log("Already checked %s" % href)
124 old_object = root_folder.linear[checked[href]]
126 "last_visit", "last_modified",
127 "error", "no_error", "moved", "size", "md5", "real_title",
128 "last_tested", "test_time", "icon", "charset",
130 if hasattr(old_object, attr_name):
131 setattr(object, attr_name,
132 getattr(old_object, attr_name))
134 log("Checking %s" % href)
135 rcode = robot.check_url(object)
138 checked[href] = object_no
139 urls_no = urls_no + 1
141 size = size + int(object.size)
142 except (AttributeError, TypeError, ValueError):
143 pass # Some object does not have a size :(
145 log("Interrupted by user (^C)")
154 print(object_count, "objects passed")
155 print(urls_no, "URLs checked")
156 print(size, "bytes eaten")
158 break_tree(root_folder.linear)
159 storage.store(root_folder)
162 log("check_urls finished ok")
166 if __name__ == '__main__':