-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenuData.py
52 lines (42 loc) · 1.83 KB
/
menuData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from urllib.request import urlopen
import sys
import webbrowser
from bs4 import BeautifulSoup
import time
import datetime
def reloadMenu():
html = urlopen("http://speiseplan.studierendenwerk-hamburg.de/en/410/2014/0/")
bsObj = BeautifulSoup(html.read(),'lxml')
nameList = bsObj.find_all('td',class_="dish-description")
nameList = [(name.get_text()).strip() for name in nameList]
masterPriceList = bsObj.find_all('td',class_="price")
masterPriceList = [(price.get_text()).strip() for price in masterPriceList]
studentPriceList = masterPriceList[0:15:3]
psPriceList = masterPriceList[1:15:3]
otherPriceList = masterPriceList[2:15:3]
return nameList, masterPriceList, studentPriceList, psPriceList, otherPriceList
def displayMenu(userInput):
dataList = reloadMenu()
menuDict = {}
#names, master prices, student prices, public servant prices, other prices
nameList = dataList[0]
studentPriceList = dataList[2]
psPriceList = dataList[3]
if datetime.datetime.now().isoweekday() in range (6,8):
return "It's the weekend, the cafeteria is closed today. Don't disturb the cooks and me!"
displayText ='The menu for today, ' + time.strftime("%d/%m/%Y")+ ', is:\n\n'
if userInput == 'student':
for name in nameList:
menuDict[name] = studentPriceList[nameList.index(name)]
for key,value in menuDict.items():
displayText = displayText + (key + "\n" + "Price: " + value + "\n" + "\n")
return (displayText)
elif userInput == 'publicservant':
for name in nameList:
menuDict[name] = psPriceList[nameList.index(name)]
for key,value in menuDict.items():
displayText = displayText + (key + "\n" + "Price: " + value + "\n" + "\n")
return (displayText)
else:
print ('Try again')
pass