SHARE
TWEET

Untitled

a guest Apr 1st, 2012 18 Never
  1. import urllib2
  2. import time
  3. url = raw_input("URL: ")
  4. url += ".json"
  5. prev = 0
  6. while True:
  7.    try:
  8.       response = urllib2.urlopen(url)
  9.    except:
  10.       break
  11.    json = response.read()
  12.    pos = json.find('num_comments')
  13.    num = int(json[pos+15:json.find(',',pos)])
  14.    if num > prev:
  15.       print "Number of comments: ", num
  16.       prev = num
  17.  
  18.  
  19.    time.sleep(1)
RAW Paste Data
Top