]> git.phdru.name Git - bookmarks_db.git/blob - check_url.py
Style: Fix flake8 E501 line too long
[bookmarks_db.git] / check_url.py
1 #! /usr/bin/env python
2 """Robot interface - check URLs from the command line
3
4 This file is a part of Bookmarks database and Internet robot.
5 """
6
7 __author__ = "Oleg Broytman <phd@phdru.name>"
8 __copyright__ = "Copyright (C) 2010-2023 PhiloSoft Design"
9 __license__ = "GNU GPL"
10
11 import sys
12 import httplib
13
14 from bkmk_objects import Bookmark
15 from Writers.bkmk_wflad import strftime
16
17 HTTP = httplib.HTTP
18
19
20 class MyHTTP(HTTP):
21     def _setup(self, conn):
22         HTTP._setup(self, conn)
23         self.set_debuglevel(1)
24
25
26 httplib.HTTP = MyHTTP
27
28
29 def run():
30     print("Broytman check_url, Copyright (C) 2010-2023 PhiloSoft Design")
31
32     if len(sys.argv) < 2:
33         sys.stderr.write("Usage: check_url.py url1 [url2...]\n")
34         sys.exit(1)
35
36     from m_lib.flog import makelog
37     log = makelog("check.log")
38
39     from robots import robot
40     robot = robot(log)
41
42     for url in sys.argv[1:]:
43         bookmark = Bookmark(href=url, add_date=None)
44         bookmark.parent = None
45
46         rcode = robot.check_url(bookmark)
47         print("check_url: %s" % rcode)
48
49         if hasattr(bookmark, 'error'):
50             print(bookmark.error)
51
52         else:
53             print("""\
54   URL: %s
55   Title: %s
56   LastModified: %s
57   IconURI: %s
58   Icon: %s
59   """ % (
60               bookmark.href, getattr(bookmark, 'real_title', ''),
61               strftime(bookmark.last_modified), bookmark.icon_href,
62               bookmark.icon))
63
64     robot.stop()
65     log.close()
66
67
68 if __name__ == '__main__':
69     run()