Last active
August 29, 2015 14:03
-
-
Save nikolajbaer/4664cb0f5a2a60961b6e to your computer and use it in GitHub Desktop.
World Cup Automatic Goal Celebration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use with this mp3 downloaded and renamed as "airhorn.mp3" | |
# http://www.freesound.org/people/mcpable/sounds/131930/ | |
# | |
import urllib,json,os,sys,time | |
goals = [] | |
while True: | |
sys.stdout.write(".") | |
sys.stdout.flush() | |
data = urllib.urlopen("http://worldcup.sfg.io/matches/today").read() | |
o = json.loads(data) | |
my_team = sys.argv[1] | |
for match in o: | |
team = None | |
if my_team == match["home_team"]["country"]: | |
team = "home_team" | |
elif my_team == match["away_team"]["country"]: | |
team = "away_team" | |
if not team: continue | |
for e in match["%s_events"%team]: | |
if e["type_of_event"] == "goal" and e["id"] not in goals: | |
print "Goal",e["id"]," registered" | |
goals.append(e["id"]) | |
os.system("afplay airhorn.mp3") | |
os.system('say "%s scored a goal"'%my_team) | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment