-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrape.py
251 lines (233 loc) · 7.29 KB
/
scrape.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
from bs4 import BeautifulSoup
import requests
def threemeals(url):
mealdata = {}
#create soup object
response = requests.get(url)
soup = BeautifulSoup(response.text)
#dinner needs a seperate loop because fucking webdevs made it a seperate class
breakfast = []
lunch = []
counter = True
for group in soup.find_all("td", { "class" : "menugridcell" }):
if counter:
for item in group.find_all("li", {"class" : "category2", "class" : "category4", "class" : "category5"}):
breakfast.append({"title" : item.get_text()})
for item in group.find_all("a", { "class" : "itemlinkt" }):
breakfast.append(item.get_text())
for item in group.find_all("a", { "class" : "itemlink" }):
breakfast.append(item.get_text())
else:
for item in group.find_all("li", {"class" : "category2", "class" : "category4", "class" : "category5"}):
lunch.append({"title" : item.get_text()})
for item in group.find_all("a", { "class" : "itemlinkt" }):
lunch.append(item.get_text())
for item in group.find_all("a", { "class" : "itemlink" }):
lunch.append(item.get_text())
if counter:
counter = False
else:
counter = True
#dinner here
dinner = []
for group in soup.find_all("td", { "class" : "menugridcell_last" }):
for item in group.find_all("li", {"class" : "category2", "class" : "category4", "class" : "category5"}):
dinner.append({"title" : item.get_text()})
for item in group.find_all("a", { "class" : "itemlinkt" }):
dinner.append(item.get_text())
for item in group.find_all("a", { "class" : "itemlink" }):
dinner.append(item.get_text())
mealdata['breakfast'] = breakfast
mealdata['lunch'] = lunch
mealdata['dinner'] = dinner
return mealdata
def twomeals(url):
mealdata = {}
#create soup object
response = requests.get(url)
soup = BeautifulSoup(response.text)
#dinner needs a seperate loop because fucking webdevs made it a seperate class
lunch = []
for group in soup.find_all("td", { "class" : "menugridcell" }):
for item in group.find_all("a", { "class" : "itemlinkt" }):
lunch.append(item.get_text())
for item in group.find_all("a", { "class" : "itemlink" }):
lunch.append(item.get_text())
#dinner here
dinner = []
for group in soup.find_all("td", { "class" : "menugridcell_last" }):
for item in group.find_all("a", { "class" : "itemlinkt" }):
dinner.append(item.get_text())
for item in group.find_all("a", { "class" : "itemlink" }):
dinner.append(item.get_text())
mealdata['breakfast'] = []
mealdata['lunch'] = lunch
mealdata['dinner'] = dinner
mealdata['latenight'] = []
return mealdata
def bcafe(url):
response = requests.get(url)
soup = BeautifulSoup(response.text)
mealdata = []
for group in soup.find_all("td", { "class" : "layouttablecell"}):
for item in group.find_all("h1"):
mealdata.append({"title" : item.get_text()})
for item in group.find_all("a", { "class" : "itemlink" }):
mealdata.append(item.get_text())
data = sortbcafe(mealdata)
return data
def sortbcafe(data):
mealdata = {}
onBreakfast = True;
onLunch = False;
onDinner = False;
spaghetti = False #omigod this is terrible, but we need to know after Lunch on the Go stops
breakfast = []
lunch = []
dinner = []
for item in data:
try:
item['title']
except TypeError:
pass
else:
if(onLunch and spaghetti):
onBreakfast = False
onLunch = True
onDinner = True
if(item['title'] == "Lunch on the Go"):
onBreakfast = False
onLunch = True
onDinner = False
spaghetti = True
if(onBreakfast):
breakfast.append(item)
if(onLunch):
lunch.append(item)
if(onDinner and spaghetti):
dinner.append(item)
#special little bit of code here to move the soup, patch fix until we regex to work...
kosher = lunch.pop(56)
lunch.insert(66, kosher)
kosher = dinner.pop(32)
dinner.insert(42, kosher)
mealdata['breakfast'] = breakfast
mealdata['lunch'] = lunch
mealdata['dinner'] = dinner
mealdata['latenight'] = dinner
return mealdata
def late(url):
response = requests.get(url)
soup = BeautifulSoup(response.text)
mealdata = []
for sectionnum in range(0,3):
switchdict = ["Entrees", "Sides", "Pizza and Wings"]
mealdata.append({"title" : switchdict[sectionnum]})
sectionid = "s" + str(sectionnum)
section = soup.find("div", { "id" : sectionid })
for item in section.find_all("a", { "class" : "itemlink" }):
mealdata.append(item.get_text())
return mealdata
def nineteen(url):
response = requests.get(url)
soup = BeautifulSoup(response.text)
mealdata = []
for sectionnum in range(0,7):
switchdict = ["Pizzette", "Panini", "Insalate", "Lasagna", "Sides", "Bibite", "Dolci"]
mealdata.append({ "title" : switchdict[sectionnum]})
sectionid = "s" + str(sectionnum)
section = soup.find("div", { "id" : sectionid })
for item in section.find_all("a", { "class" : "itemlink" }):
mealdata.append(item.get_text())
data = sortnineteen(mealdata)
return data
def sortnineteen(data):
mealdata = {}
onBreakfast = False;
onLunch = True;
onDinner = True;
breakfast = []
lunch = []
dinner = []
for item in data:
try:
item['title']
except TypeError:
pass
else:
if(item['title'] == "Lasagna"):
onBreakfast = False
onLunch = False
onDinner = True
if(item['title'] == "Sides"):
onBreakfast = False
onLunch = True
onDinner = True
if(onBreakfast):
breakfast.append(item)
if(onLunch):
lunch.append(item)
if(onDinner):
dinner.append(item)
mealdata['breakfast'] = []
mealdata['lunch'] = lunch
mealdata['dinner'] = dinner
mealdata['latenight'] = dinner
return mealdata
def rende(url):
response = requests.get(url)
soup = BeautifulSoup(response.text)
mealdata = []
for sectionnum in range(0,3):
switchdict = ["Breakfast", "Mexican", "Asian"]
mealdata.append({ "title" : switchdict[sectionnum]})
sectionid = "s" + str(sectionnum)
section = soup.find("div", { "id" : sectionid})
for item in section.find_all("a", { "class" : "itemlink" }):
if sectionnum is 0 and item.get_text() == "Apple Juice":
mealdata.append({ "title" : "Beverages"})
if sectionnum is 0 and item.get_text() == "Oatmeal":
mealdata.append({ "title" : "Express Breakfast"})
if sectionnum > 0 and item.get_text() == "Fountain Beverage":
mealdata.append({ "title" : "Beverages"})
if item.get_text():
mealdata.append(item.get_text())
truemealdata = sortrende(mealdata) #look we be sorting it
return truemealdata
def sortrende(rendedata):
mealdata = {}
onBreakfast = True;
onLunch = False;
onDinner = False;
breakfast = []
lunch = []
dinner = []
for item in rendedata:
try:
item['title']
except TypeError:
pass
else:
if(item['title'] == "Mexican"):
onBreakfast = False
onLunch = True
onDinner = True
if(onBreakfast):
breakfast.append(item)
if(onLunch):
lunch.append(item)
if(onDinner):
dinner.append(item)
mealdata['breakfast'] = breakfast
mealdata['lunch'] = lunch
mealdata['dinner'] = dinner
mealdata['latenight'] = dinner
return mealdata
#----LOLLLLL------
def hedrick():
mealData = {}
mealData['breakfast'] = ["We wish we knew, but there's no data online so :("]
mealData['lunch'] = ["We wish we knew, but there's no data online so :("]
mealData['dinner'] = ["We wish we knew, but there's no data online so :("]
mealData['latenight'] = ["We wish we knew, but there's no data online so :("]
return mealData