Skip to content

Instantly share code, notes, and snippets.

@tinnet
Created September 7, 2011 16:42
Show Gist options
  • Save tinnet/1201066 to your computer and use it in GitHub Desktop.
Save tinnet/1201066 to your computer and use it in GitHub Desktop.
radio7 watcher...
import time
import urllib2
from BeautifulSoup import BeautifulSoup
from pygame import mixer
log = open("radio7.log", "a")
mixer.init()
alert = mixer.Sound('alarm.wav')
lastpic = ""
while True:
html = urllib2.urlopen("http://www.radio7.de/index.php?id=1687").read()
soup = BeautifulSoup(html)
for img in soup.findAll("img"):
if img.has_key("width") and img["width"] == "516" and img["height"] == "196":
pic = img["src"]
if pic != lastpic and lastpic != "":
alarm = " ALARM!"
alert.play(loops=-1,maxtime=15000)
else:
alarm = ""
print "{0} {1} {2}".format(time.strftime("%Y-%m-%d %H:%M:%S"), pic, alarm)
log.write("{0} {1} {2}\n".format(time.strftime("%Y-%m-%d %H:%M:%S"), pic, alarm))
log.flush()
lastpic = img["src"]
time.sleep(3)
log.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment