Support for WestSideDiner and Burgerbar | New structre

This commit is contained in:
mmk2410 2015-12-13 09:19:45 +01:00
parent 3c7b65a1e0
commit b785414766
1 changed files with 95 additions and 58 deletions

View File

@ -8,71 +8,108 @@ import urllib.request
import json import json
import datetime import datetime
def get(): FILES = [
""" "http://www.uni-ulm.de/mensaplan/data/mensaplan.json",
Recieving the JSON file from uulm "http://www.uni-ulm.de/mensaplan/data/mensaplan_static.json"
]
return json data def print_usage():
"""Print the help text"""
print("Usage:")
usage = """
./mensaplan.py place
Print the todays menu at the place.
./mensaplan.py place [mon, thu, wed, thur, fri]
Print the menu at the place of the given weekday.
Supported places are:
Mensa University: mensa
Bistro: bistro
Burgerbar Southside: burgerbar
CafeteriaB: cafeteriab
Cafeteria West: west
West Side Diner: westside
Mensa Hochschule: hochschule
""" """
url = "http://www.uni-ulm.de/mensaplan/data/mensaplan.json" print(usage)
print("mmk2410 (c) 2015 MIT License")
def get(url):
"""Recieving the JSON file from uulm"""
response = urllib.request.urlopen(url) response = urllib.request.urlopen(url)
data = response.read() data = response.read()
data = data.decode("utf-8") data = data.decode("utf-8")
data = json.loads(data) data = json.loads(data)
return data return data
def print_usage(): def get_day():
""" """Function for retrieving the wanted day"""
Print the help text day = datetime.datetime.today().weekday()
""" if len(sys.argv) == 3:
print("Usage:") if sys.argv[2] == "mon":
usage = """ day = 0
./mensaplan.py elif sys.argv[2] == "thu":
Print the todays menu. day = 1
elif sys.argv[2] == "wed":
./mensaplan.py print [mon, thu, wed, thur, fri] day = 2
Print the menu of the given weekday. elif sys.argv[2] == "thur":
""" day = 3
print(usage) elif sys.argv[2] == "fri":
print("mmk2410 (c) 2015 MIT License") day = 4
else:
if len(sys.argv) >= 2: day = 5
cmd = sys.argv[1] if day > 4:
if cmd == "help": print("There is no information about the menu today.")
print_usage() exit(5)
else: return day
if cmd == "mensa":
place = "Mensa" def print_menu(place, static=False):
elif cmd == "bistro": """Function for printing the menu
place = "Bistro"
elif cmd == "cafeteriab": Keyword arguments:
place = "CB" place -- name of the cafeteria / mensa
elif cmd == "west": static -- set true if a static menu exists (default: False)
place = "West" """
elif cmd == "hochschule": if static:
place = "Prittwitzstr" plan = get(FILES[1])
week = 0
else:
plan = get(FILES[0])
week = 1
day = get_day()
for meal in plan["weeks"][week]["days"][day][place]["meals"]:
if place == "Diner":
print(meal["category"] + " " + meal["meal"])
else: else:
print("You have to give a place as a agrument")
plan = get()
print("Menu:")
day = datetime.datetime.today().weekday()
if len(sys.argv) == 3:
if sys.argv[2] == "mon":
day = 0
elif sys.argv[2] == "thu":
day = 1
elif sys.argv[2] == "wed":
day = 2
elif sys.argv[2] == "thur":
day = 3
elif sys.argv[2] == "fri":
day = 4
else:
day = 5
if day > 4:
print("There is no information about the menu today.")
exit(5)
for meal in plan["weeks"][1]["days"][day][place]["meals"]:
print(meal["category"] + ": " + meal["meal"]) print(meal["category"] + ": " + meal["meal"])
else:
print_usage() def main():
"""Main function"""
if len(sys.argv) >= 2:
cmd = sys.argv[1]
if cmd == "help":
print_usage()
else:
if cmd == "mensa":
print_menu("Mensa")
elif cmd == "bistro":
print_menu("Bistro")
elif cmd == "cafeteriab":
print_menu("CB")
elif cmd == "west":
print_menu("West")
elif cmd == "hochschule":
print_menu("Prittwitzstr")
elif cmd == "westside":
print_menu("Diner", True)
elif cmd == "burgerbar":
print_menu("Burgerbar", True)
else:
print("[ERROR]: No valid place given")
print_usage()
else:
print("[ERROR]: No argument given")
print_usage()
main()