Skip to content

Instantly share code, notes, and snippets.

@u1735067
Last active August 29, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save u1735067/fcf1d52b5ccce20ec3eb to your computer and use it in GitHub Desktop.
Save u1735067/fcf1d52b5ccce20ec3eb to your computer and use it in GitHub Desktop.
Botanik - rak.py
#!/usr/bin/env python3
import urllib.request, json
from datetime import datetime, timedelta, date, time
url='http://resel.fr/services/rak/menu.json'
error = "Désolé, le RAK n'a pas publié le menu ou il s'est produit une erreur :("
prefix = 'Au menu du RAK'
next = 'suivi de'
finish = 'terminé par'
try:
response = urllib.request.urlopen(url)
str_response = response.readall().decode('utf-8')
menus = json.loads(str_response)
day = date.today()
if (datetime.now().hour < 13):
meal = 'lunch'
quand = 'ce midi'
elif (datetime.now().hour < 20):
meal = 'dinner'
quand = 'ce soir'
else:
day = day+timedelta(days=1)
meal = 'lunch'
quand = 'demain midi'
menu = menus[str(day)][meal]
if (meal == 'dinner'):
print(prefix+' '+quand+' : '+menu['starter']+', '+next+' '+menu['main'])
else:
print(prefix+' '+quand+' : '+menu['starter']+', '+next+' '+menu['main']+', '+finish+' '+menu['dessert'])
except:
print(error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment