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")
65 from storage import storage
68 from robots import robot
72 sys.stdout.write("Loading %s: " % storage.filename)
75 root_folder = storage.load()
76 from bkmk_objects import make_linear, break_tree
77 make_linear(root_folder)
78 objects = len(root_folder.linear)
85 s = "Rechecking errors: "
92 pbar = ttyProgressBar(0, objects)
101 for object_no in range(objects):
103 pbar.display(object_no+1)
105 object = root_folder.linear[object_no]
106 object_count = object_count + 1
108 if object.isBookmark:
110 if (href.startswith('place:') # Firefox SmartBookmarks
111 or '%s' in href): # Bookmark with keyword
112 log("Skipped %s" % href)
116 if hasattr(object, "error"):
117 delattr(object, "error")
121 if checked.has_key(href):
122 log("Already checked %s" % href)
123 old_object = root_folder.linear[checked[href]]
125 "last_visit", "last_modified",
126 "error", "no_error", "moved", "size", "md5", "real_title",
127 "last_tested", "test_time", "icon", "charset",
129 if hasattr(old_object, attr_name):
130 setattr(object, attr_name,
131 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__':