Skip to content

Instantly share code, notes, and snippets.

@whs
Created April 18, 2011 13:44
Show Gist options
  • Save whs/925356 to your computer and use it in GitHub Desktop.
Save whs/925356 to your computer and use it in GitHub Desktop.
GLaDOS@Home alarm clock
#!/usr/bin/python
# READ FIRST
# This software poll HP2LY every 5 minutes and will play
# any ffmpeg supported file 20 times after 95%.
# To quit press Ctrl+C in Terminal.
# Closing ffplay would just respawn it.
#
# Dependency:
# Ubuntu: sudo apt-get install ffmpeg
# Fedora: su -c 'yum install ffmpeg'
# Mac OS X: Install MacPorts and sudo ports install ffmpeg
song = r"~/stillalive.mp4"
percent = 95
import urllib, commands, os, sys, time
from json import loads
while True:
p = urllib.urlopen("http://hasportal2launchedyet.com/data.json").read()
json = loads(p)
print "%s%% -- %s est. %s" % (
json['overall'],
time.ctime(time.time() + json['glados']['endpoint']),
time.ctime(time.time() + json['estimate']['endpoint'])
)
if json['overall'] > percent:
if sys.platform == "darwin":
# Mac: set volume to max
os.system("osascript -e 'set volume 7'")
else:
# Linux: set volume to max
os.system("amixer sset 'Master' 36 31")
for i in range(20):
print commands.getoutput("ffplay '"+os.path.expanduser(song)+"'")
break
time.sleep(60*5)
@whs
Copy link
Author

whs commented Apr 18, 2011

Oops, forgot that json is not available in Python2.5 on Mac OS X.

Mac users: Please install Python 2.6 or later or run following commands
sudo ports install py25-setuptools
sudo easy_install simplejson
After that change line 17 to "from simplejson import loads" (without quotes)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment