Skip to content

Instantly share code, notes, and snippets.

@nikolajbaer
Last active August 29, 2015 14:03
Show Gist options
  • Save nikolajbaer/4664cb0f5a2a60961b6e to your computer and use it in GitHub Desktop.
Save nikolajbaer/4664cb0f5a2a60961b6e to your computer and use it in GitHub Desktop.
World Cup Automatic Goal Celebration
# 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