Last active
August 29, 2015 14:19
-
-
Save u1735067/fcf1d52b5ccce20ec3eb to your computer and use it in GitHub Desktop.
Botanik - rak.py
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
#!/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