#! /usr/bin/env python
-"""
- Robot interface - check URLs from bookmarks database
+"""Robot interface - check URLs from bookmarks database
- Written by BroytMann. Copyright (C) 2000-2007 PhiloSoft Design.
+This file is a part of Bookmarks database and Internet robot.
"""
+from __future__ import print_function
+import sys, os
+
-import sys, os, tempfile
-tempfname = "check_urls" + tempfile.gettempprefix() + "tmp"
+__author__ = "Oleg Broytman <phd@phdru.name>"
+__copyright__ = "Copyright (C) 2000-2017 PhiloSoft Design"
+__license__ = "GNU GPL"
def run():
pass
if report_stats:
- print "BroytMann check_urls, Copyright (C) 1997-2007 PhiloSoft Design"
+ print("Broytman check_urls, Copyright (C) 1997-2017 PhiloSoft Design")
if args:
sys.stderr.write("check_urls: too many arguments\n")
log = openlog("check.log")
log("chk_urls restarted for errors")
if report_stats:
- print "chk_urls restarted for errors"
+ print("chk_urls restarted for errors")
else:
log = makelog("check.log")
log("check_urls started")
if report_stats:
- print " check_urls: normal start"
+ print(" check_urls: normal start")
from storage import storage
storage = storage()
from robots import robot
- robot = robot(tempfname, log)
+ robot = robot(log)
if report_stats:
sys.stdout.write("Loading %s: " % storage.filename)
objects = len(root_folder.linear)
if report_stats:
- print "Ok"
+ print("Ok")
if report_stats:
if only_errors:
object_count = object_count + 1
if object.isBookmark:
+ href = object.href
+ if (href.startswith('place:') # Firefox SmartBookmarks
+ or '%s' in href): # Bookmark with keyword
+ log("Skipped %s" % href)
+ continue
+
if only_errors:
if hasattr(object, "error"):
delattr(object, "error")
else:
continue
- if checked.has_key(object.href):
- log("Already checked %s" % object.href)
- old_object = root_folder.linear[checked[object.href]]
+ if checked.has_key(href):
+ log("Already checked %s" % href)
+ old_object = root_folder.linear[checked[href]]
for attr_name in ("last_visit", "last_modified",
"error", "no_error", "moved", "size", "md5", "real_title",
"last_tested", "test_time", "icon", "charset"):
if hasattr(old_object, attr_name):
setattr(object, attr_name, getattr(old_object, attr_name))
else:
- log("Checking %s" % object.href)
+ log("Checking %s" % href)
rcode = robot.check_url(object)
if rcode:
- checked[object.href] = object_no
+ checked[href] = object_no
urls_no = urls_no + 1
try:
size = size + int(object.size)
del pbar
if report_stats:
- print "Ok"
- print object_count, "objects passed"
- print urls_no, "URLs checked"
- print size, "bytes eaten"
+ print("Ok")
+ print(object_count, "objects passed")
+ print(urls_no, "URLs checked")
+ print(size, "bytes eaten")
break_tree(root_folder.linear)
storage.store(root_folder)
log("check_urls finished ok")
log.close()
- try:
- os.unlink(tempfname)
- except os.error:
- pass
-
if __name__ == '__main__':
run()