]> git.phdru.name Git - bookmarks_db.git/commitdiff
Added check_url.py to check URLs one by one from the command line verbosely.
authorOleg Broytman <phd@phdru.name>
Tue, 10 Aug 2010 09:46:14 +0000 (09:46 +0000)
committerOleg Broytman <phd@phdru.name>
Tue, 10 Aug 2010 09:46:14 +0000 (09:46 +0000)
git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@250 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23

Makefile
check_url.py [new file with mode: 0755]

index 808c17cc6598fd1c2d60cbda06e3158caba761bd..fcbb0501b7c7e759de04c7b7cd16df960c606aef 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ VERSION=4.2.0
 
 EXAMPLE_SHELL=ns-unescape mz-unescape bkmk2db koi2win.db \
        bkmk-koi bkmk-win bkmk-chk bkmk-publish bkmk-sort hotexplode.pl \
-       check_title.py set-real_title.py set-title-list.py \
+       check_url.py check_title.py set-real_title.py set-title-list.py \
        bkmk-add.py bkmk-add bkmk-rsync mz2ns mk-distr
 
 
diff --git a/check_url.py b/check_url.py
new file mode 100755 (executable)
index 0000000..18e3397
--- /dev/null
@@ -0,0 +1,62 @@
+#! /usr/bin/env python
+"""
+   Robot interface - check one URL
+
+   Written by Broytman. Copyright (C) 2010 PhiloSoft Design.
+"""
+
+
+import sys
+import httplib
+
+HTTP = httplib.HTTP
+
+class MyHTTP(HTTP):
+    def _setup(self, conn):
+        HTTP._setup(self, conn)
+        self.set_debuglevel(1)
+
+httplib.HTTP = MyHTTP
+
+from bkmk_objects import Bookmark
+from Writers.bkmk_wflad import strftime
+tempfname = "check_url.tmp"
+
+
+def run():
+   print "Broytman check_url, Copyright (C) 2010 PhiloSoft Design"
+
+   if len(sys.argv) < 2:
+      sys.stderr.write("Usage: check_url.py url1 [url2...]\n")
+      sys.exit(1)
+
+   from m_lib.flog import makelog
+   log = makelog("check.log")
+
+   from robots import robot
+   robot = robot(tempfname, log)
+
+   for url in sys.argv[1:]:
+       bookmark = Bookmark(href=url, add_date=None)
+       bookmark.parent = None
+
+       rcode = robot.check_url(bookmark)
+       print "check_url: %s" % rcode
+
+       if hasattr(bookmark, 'error'):
+          print bookmark.error
+
+       else:
+          print """\
+URL: %s
+Title: %s
+LastModified: %s
+Icon: %s
+""" % (bookmark.href, getattr(bookmark, 'name', ''), strftime(bookmark.last_modified), bookmark.icon)
+
+   robot.stop()
+   log.close()
+
+
+if __name__ == '__main__':
+   run()