URI: 
       tz-webcam - annna - Annna the nice friendly bot.
  HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
       ---
       tz-webcam (1762B)
       ---
            1 #!/usr/bin/env python
            2 # coding=utf-8
            3 #
            4 
            5 import io
            6 import os
            7 import sys
            8 import getopt
            9 import requests
           10 import random
           11 from lxml import etree
           12 
           13 def usage(app):
           14     app = os.path.basename(app)
           15     print("usage: %s [-h] [--] [-]XX:XX" % (app), file=sys.stderr)
           16     sys.exit(1)
           17 
           18 def main(args):
           19     try:
           20         opts, largs = getopt.getopt(args[1:], "h")
           21     except getopt.GetoptError as err:
           22         print(str(err))
           23         usage(args[0])
           24 
           25     for o, a in opts:
           26         if o == "-h":
           27             usage(args[0])
           28         else:
           29             assert False, "unhandled option"
           30 
           31     tzstr = largs[0]
           32     if tzstr == "+00:00" or tzstr == "-00:00":
           33         tzstr = "-"
           34 
           35     headers = {
           36         "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
           37     }
           38 
           39     try:
           40         page = requests.get("http://www.insecam.org/en/bytimezone/%s/" % (tzstr),\
           41                 headers=headers)
           42         xml = etree.parse(io.StringIO(page.text), etree.HTMLParser())
           43         pages = int(xml.xpath("//nav[@class=\"navigation\"]/ul/script")[0].text.strip().split(",")[1].strip())
           44         randpage = random.randint(1, pages)
           45         if randpage != 1:
           46             page = requests.get("http://www.insecam.org/en/bytimezone/%s/?page=%d" % (tzstr, randpage),\
           47                     headers=headers)
           48             xml = etree.parse(io.StringIO(page.text), etree.HTMLParser())
           49         imgitem = random.choice(xml.xpath("//img"))
           50         uri = imgitem.attrib["src"]
           51         if not uri.startswith("http"):
           52             imgitem = random.choice(xml.xpath("//img"))
           53             uri = imgitem.attrib["src"]
           54         print("%s" % (uri))
           55         return 0
           56     except:
           57         return 1
           58 
           59 if __name__ == "__main__":
           60     sys.exit(main(sys.argv))
           61