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
12 __author__ = "Oleg Broytman <phd@phdru.name>"
13 __copyright__ = "Copyright (C) 2000-2023 PhiloSoft Design"
14 __license__ = "GNU GPL"
18 from getopt import getopt
19 optlist, args = getopt(sys.argv[1:], "ise")
25 for _opt, _arg in optlist:
38 print("Broytman check_urls, Copyright (C) 1997-2023 PhiloSoft Design")
41 sys.stderr.write("check_urls: too many arguments\n")
42 sys.stderr.write("Usage: check_urls [-ise]\n")
46 show_pbar = sys.stderr.isatty()
50 from m_lib.pbar.tty_pbar import ttyProgressBar
54 from m_lib.flog import makelog, openlog
56 log = openlog("check.log")
57 log("chk_urls restarted for errors")
59 print("chk_urls restarted for errors")
61 log = makelog("check.log")
62 log("check_urls started")
64 print(" check_urls: normal start")
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")
122 if checked.has_key(href):
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, getattr(old_object, attr_name))
133 log("Checking %s" % href)
134 rcode = robot.check_url(object)
137 checked[href] = object_no
138 urls_no = urls_no + 1
140 size = size + int(object.size)
141 except (AttributeError, TypeError, ValueError):
142 pass # Some object does not have a size :(
144 log("Interrupted by user (^C)")
153 print(object_count, "objects passed")
154 print(urls_no, "URLs checked")
155 print(size, "bytes eaten")
157 break_tree(root_folder.linear)
158 storage.store(root_folder)
161 log("check_urls finished ok")
165 if __name__ == '__main__':