Just eat strat

This commit is contained in:
Alexander Munch-Hansen 2019-04-06 19:53:26 +02:00
parent ef1884445a
commit 565e83d92f
2 changed files with 33 additions and 5 deletions

View File

@ -3,15 +3,43 @@ from bs4 import BeautifulSoup
from datetime import datetime, timedelta
import requests_cache
from ..util import Context, Prediction
requests_cache.install_cache("requests_cache", expire_after=timedelta(minutes=10))
def is_restaurant_open(name):
def is_restaurant_open(name, open, close) -> Prediction:
p = Prediction()
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'}
r = requests.get("https://www.just-eat.dk/area/8000-århusc", headers=headers)
soup = BeautifulSoup(r.content, features='html5lib')
print(soup.prettify())
print(soup.find('div', {'class': 'listing-group'}))
listing_groups = soup.find_all('div', {'class': 'listing-group'})
is_restaurant_open("lel")
p.reasons.append("Hopefully we are not banned from Just-eat ..")
nice_group = None
for x in listing_groups:
if x['data-test-id'] == 'listingGroupOpen':
nice_group = x
if nice_group is None:
p.reasons.append("Apparently we are banned from just-eat. We therefore have no clue.")
p.probability = 0.5
return p
all_listings = nice_group.find_all('a', {'class': 'mediaElement'})
if any(name in x['href'] for x in all_listings):
p.reasons.append(f"{name} is currently open. We conclude from this, that there is {1 / 11}% chance of it being night outside!")
p.probability = 1 / 11
else:
p.reasons.append(f"{name} is not open. We can conclude from this, that there is {1 - (1/11)}% chance of it currently being night outside! ")
p.probability = 1 - (1 / 11)
return p
def do_just_eat_strat(context: Context) -> Prediction:
return is_restaurant_open('stop2shop', 12, 23)