Skip to content

Instantly share code, notes, and snippets.

@wrboyce
Created March 28, 2011 14:43
Show Gist options
  • Select an option

  • Save wrboyce/890586 to your computer and use it in GitHub Desktop.

Select an option

Save wrboyce/890586 to your computer and use it in GitHub Desktop.
from datetime import datetime
import hashlib
import time
import urllib
def main():
fn = 'current-%s.jpg' % datetime.now().strftime('%Y%m%d%H%M')
lasthash = file('LATEST', 'r').read().strip()
thishash, thisfile = None, None
while True:
thisfile = urllib.urlopen('http://www.doncaster.gov.uk/webcam/current.jpg').read()
thishash = hashlib.md5(thisfile).hexdigest()
if lasthash != thishash:
break
time.sleep(30) # sleep for 30 seconds
file(fn, 'w').write(thisfile)
file('LATEST', 'w').write(thishash)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment