From: Oleg Broytman Date: Tue, 10 Aug 2010 09:46:14 +0000 (+0000) Subject: Added check_url.py to check URLs one by one from the command line verbosely. X-Git-Tag: v4.5.3~126 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=36ade7b93a4a85c265f095844fb8ce5c5f6d79f3;p=bookmarks_db.git Added check_url.py to check URLs one by one from the command line verbosely. git-svn-id: file:///home/phd/archive/SVN/bookmarks_db/trunk@250 fdd5c36f-1aea-0310-aeeb-c58d7e2b6c23 --- diff --git a/Makefile b/Makefile index 808c17c..fcbb050 100644 --- 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 index 0000000..18e3397 --- /dev/null +++ b/check_url.py @@ -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()