Untitled

From Idiotic Hog, 2 Years ago, written in PHP, viewed 103 times.
URL https://paste.bugabuse.net/view/62ae2689 Embed
Download Paste or View Raw
  1. import urllib2
  2. import re
  3. import scraperwiki
  4. import datetime
  5. import lxml.html
  6. import hotshot
  7.  
  8. ipextract = re.compile('rtmp://(?P<IP>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+):443/tinyconf')
  9.  
  10. def getrooms(n):
  11.  
  12.     ## Get list of tinychat room names from page n of the public listing
  13.    response = urllib2.urlopen("http://tinychat.com/channel?frame=true&page=" + n)
  14.     html = response.read()
  15.  
  16.     ## Method 1 of extracting room names, using the string find function
  17.    #x = 0
  18.    #i1 = 0
  19.    #i2 = 0
  20.    #x = html.find('picwrapper')
  21.    #while x > -1 and i1 > -1 and i2 > -1:
  22.    #    i1 = html.find("<span class='blip_live'>Live</span>\n   <b><a href=", x)
  23.    #    i2 = html.find('>', i1+52)
  24.    #    if i1>-1 and i2>-1:
  25.    #        s.add(html[i1+52:i2-1])
  26.    #    x = i2
  27.  
  28.     ## Method 2 of extracting room names, using lxml
  29.    root = lxml.html.fromstring(html)
  30.     for el in root.find_class('avatar'):
  31.         room_name = el.iterlinks().next()[2][1:]
  32.         getip(room_name)
  33.  
  34. def getip(room_name):
  35.  
  36.     # to add: if room closed or with password, remove it
  37.  
  38.     ## Get configuration of tinychat room called roomname
  39.    response = urllib2.urlopen('http://tinychat.com/api/find.room/' + room_name)
  40.     room_config = response.read()
  41.    
  42.     ## Method 2 for extracting IP address, using a regular expression
  43.    match = ipextract.search(room_config)
  44.     if not match:
  45.         ## Room seems to be closed or now has password
  46.        return
  47.     ip = match.group('IP')
  48.    
  49.     scraperwiki.sqlite.execute("INSERT INTO associations values(NULL,?,?,?)", (ip, room_name, str(datetime.datetime.now())))
  50.  
  51. def maintain():
  52.     scraperwiki.sqlite.execute("DROP TABLE associations")
  53.     scraperwiki.sqlite.execute("CREATE TABLE associations (id INTEGER PRIMARY KEY AUTOINCREMENT, ip TEXT, room TEXT, date TEXT)")
  54.  
  55. def get():
  56.     for i in range(50):
  57.         getrooms(str(i))
  58.         scraperwiki.sqlite.commit()
  59.  
  60. #maintain()
  61. get()
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  

Reply to "Untitled"

Here you can reply to the paste above