This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 1st, 2012  |  syntax: Python  |  size: 0.37 KB  |  views: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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)
clone this paste RAW Paste Data