forked from QECProgramming/team4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
skipthedishes.py
57 lines (42 loc) · 1.74 KB
/
skipthedishes.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
from bs4 import BeautifulSoup
from selenium import webdriver
import re
class SkipTheDishes:
def find(size, quantity, toppings):
url = "https://www.skipthedishes.com/"
browser = webdriver.Chrome()
browser.get(url + "kingston/restaurants" + "?search=pizza")
html = browser.page_source
soup = BeautifulSoup(html, "lxml")
searchResults = []
for resto in soup.find_all("a", class_="restaurant-list"):
content = resto.findAll('div', class_="list-content")
headings = content[0].find_all("div")
ratings = content[1].find_all("div")
searchResults.append({
'name': headings[0].string,
'address': headings[1].string,
'rating': ratings[0].string,
'href': resto["href"]
})
searchResults.reverse()
browser.get(url + searchResults[0]["href"])
html = browser.page_source
soup = BeautifulSoup(html, "lxml")
pizzas = []
for row in soup.find_all('div', class_="row menu-group"):
categoryName = row.find('h3', class_="category-name").string.lower()
if categoryName.find("pizza") == -1:
continue
if categoryName.find(size.lower()) == -1:
continue
prices = []
for priceRow in row.find_all('td', 'menu-item-price'):
prices.append(
float(re.findall("\d+\.\d+", priceRow.div.strong.string)[0])
)
averagePrice = 0
for price in prices:
averagePrice += price
averagePrice = averagePrice / len(prices)
return (averagePrice * quantity) + (1.75 * toppings)