Support for WestSideDiner and Burgerbar | New structre
This commit is contained in:
parent
3c7b65a1e0
commit
b785414766
1 changed files with 95 additions and 58 deletions
153
mensaplan.py
153
mensaplan.py
|
@ -8,71 +8,108 @@ import urllib.request
|
|||
import json
|
||||
import datetime
|
||||
|
||||
def get():
|
||||
"""
|
||||
Recieving the JSON file from uulm
|
||||
FILES = [
|
||||
"http://www.uni-ulm.de/mensaplan/data/mensaplan.json",
|
||||
"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)
|
||||
data = response.read()
|
||||
data = data.decode("utf-8")
|
||||
data = json.loads(data)
|
||||
return data
|
||||
|
||||
def print_usage():
|
||||
"""
|
||||
Print the help text
|
||||
"""
|
||||
print("Usage:")
|
||||
usage = """
|
||||
./mensaplan.py
|
||||
Print the todays menu.
|
||||
|
||||
./mensaplan.py print [mon, thu, wed, thur, fri]
|
||||
Print the menu of the given weekday.
|
||||
"""
|
||||
print(usage)
|
||||
print("mmk2410 (c) 2015 MIT License")
|
||||
|
||||
if len(sys.argv) >= 2:
|
||||
cmd = sys.argv[1]
|
||||
if cmd == "help":
|
||||
print_usage()
|
||||
else:
|
||||
if cmd == "mensa":
|
||||
place = "Mensa"
|
||||
elif cmd == "bistro":
|
||||
place = "Bistro"
|
||||
elif cmd == "cafeteriab":
|
||||
place = "CB"
|
||||
elif cmd == "west":
|
||||
place = "West"
|
||||
elif cmd == "hochschule":
|
||||
place = "Prittwitzstr"
|
||||
def get_day():
|
||||
"""Function for retrieving the wanted day"""
|
||||
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)
|
||||
return day
|
||||
|
||||
def print_menu(place, static=False):
|
||||
"""Function for printing the menu
|
||||
|
||||
Keyword arguments:
|
||||
place -- name of the cafeteria / mensa
|
||||
static -- set true if a static menu exists (default: False)
|
||||
"""
|
||||
if static:
|
||||
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:
|
||||
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"])
|
||||
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()
|
||||
|
|
Reference in a new issue