Style improvements
This commit is contained in:
parent
828ea667f8
commit
96dda8c965
1 changed files with 10 additions and 5 deletions
15
mensaplan.py
15
mensaplan.py
|
@ -9,6 +9,11 @@ import json
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
def get():
|
def get():
|
||||||
|
"""
|
||||||
|
Recieving the JSON file from uulm
|
||||||
|
|
||||||
|
return json data
|
||||||
|
"""
|
||||||
url = "http://www.uni-ulm.de/mensaplan/data/mensaplan.json"
|
url = "http://www.uni-ulm.de/mensaplan/data/mensaplan.json"
|
||||||
response = urllib.request.urlopen(url)
|
response = urllib.request.urlopen(url)
|
||||||
data = response.read()
|
data = response.read()
|
||||||
|
@ -16,10 +21,10 @@ def get():
|
||||||
data = json.loads(data)
|
data = json.loads(data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def print_mensa():
|
|
||||||
print("Mensaplan")
|
|
||||||
|
|
||||||
def print_usage():
|
def print_usage():
|
||||||
|
"""
|
||||||
|
Print the help text
|
||||||
|
"""
|
||||||
print("Usage:")
|
print("Usage:")
|
||||||
usage = """
|
usage = """
|
||||||
./mensaplan.py print
|
./mensaplan.py print
|
||||||
|
@ -35,7 +40,7 @@ if len(sys.argv) >= 2:
|
||||||
cmd = sys.argv[1]
|
cmd = sys.argv[1]
|
||||||
if cmd == "print":
|
if cmd == "print":
|
||||||
plan = get()
|
plan = get()
|
||||||
print_mensa()
|
print("Mensplan:")
|
||||||
day = datetime.datetime.today().weekday()
|
day = datetime.datetime.today().weekday()
|
||||||
if len(sys.argv) == 3:
|
if len(sys.argv) == 3:
|
||||||
if sys.argv[2] == "mon":
|
if sys.argv[2] == "mon":
|
||||||
|
@ -52,7 +57,7 @@ if len(sys.argv) >= 2:
|
||||||
day = 5
|
day = 5
|
||||||
if day > 4:
|
if day > 4:
|
||||||
print("Heute gibt es nichts zu essen. Bloed gelaufen :(")
|
print("Heute gibt es nichts zu essen. Bloed gelaufen :(")
|
||||||
exit(5);
|
exit(5)
|
||||||
for meal in plan["weeks"][1]["days"][day]["Mensa"]["meals"]:
|
for meal in plan["weeks"][1]["days"][day]["Mensa"]["meals"]:
|
||||||
print(meal["category"] + ": " + meal["meal"])
|
print(meal["category"] + ": " + meal["meal"])
|
||||||
else:
|
else:
|
||||||
|
|
Reference in a new issue