From: Oleg Broytman Date: Wed, 7 Aug 2024 17:00:53 +0000 (+0300) Subject: Feat(Robots): Stop the robot ASAP X-Git-Tag: 5.6.0~6 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=6a7687a10e33df091516a19f2e3535b25d67eade;p=bookmarks_db.git Feat(Robots): Stop the robot ASAP Process bookmarks after the robot stopped. In the future there will be robots that check multiple URLs in parallel so bookmarks cannot be processed inside check loop but can be queried after. --- diff --git a/check_urls.py b/check_urls.py index e7d68f9..103553a 100755 --- a/check_urls.py +++ b/check_urls.py @@ -44,12 +44,18 @@ def run(): print("Using", robot) robot = robot(log) + bookmarks = [] for url in sys.argv[1:]: bookmark = Bookmark(href=url, add_date=None) bookmark.parent = None + bookmarks.append(bookmark) robot.check_bookmark(bookmark) + robot.stop() + log.close() + + for bookmark in bookmarks: if hasattr(bookmark, 'error'): print(bookmark.error) @@ -76,9 +82,6 @@ def run(): ) ) - robot.stop() - log.close() - if __name__ == '__main__': run() diff --git a/check_urls_db.py b/check_urls_db.py index 515bbfc..53827f3 100755 --- a/check_urls_db.py +++ b/check_urls_db.py @@ -137,12 +137,16 @@ def run(): checked[href] = object_no urls_no = urls_no + 1 - try: - size = size + int(object.size) - except (AttributeError, TypeError, ValueError): - pass # Some object does not have a size :( robot.stop() + for object_no in range(objects): + object = root_folder.linear[object_no] + if object.isBookmark: + try: + size = size + int(object.size) + except (AttributeError, TypeError, ValueError): + pass # Some object does not have a size :( + if show_pbar: del pbar diff --git a/get_url.py b/get_url.py index 2a411e5..86a58f6 100755 --- a/get_url.py +++ b/get_url.py @@ -33,6 +33,7 @@ def run(): error, redirect_code, redirect_to, headers, content = \ robot.get_url(bookmark, url, True) + robot.stop() if error: sys.stderr.write(error + '\n') @@ -53,8 +54,6 @@ def run(): else: print(content) - robot.stop() - if __name__ == '__main__': run()