nightr/server/nightr/strategies/just_eat.py

47 lines
1.7 KiB
Python

import requests
from bs4 import BeautifulSoup
from ..util import Context, Prediction
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')
listing_groups = soup.find_all('div', {'class': 'listing-group'})
#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"Our favorite pizza place, {name}, is currently open.")
p.reasons.append(f"We conclude from this, that there is {1 / 11}% chance of it being night outside")
p.probability = 1 / 11
else:
p.reasons.append(f"Our favorite pizza place, {name}, is closed.")
p.reasons.append(f"We can conclude from this, that there is {1 - (1/11):.1f}% chance of it currently being night outside!")
p.probability = round(1 - (1 / 11), 2)
return p
def do_just_eat_strat(context: Context) -> Prediction:
"""
Is this random Kiosk in Vester Alle open?
"""
return is_restaurant_open('stop2shop', 12, 23)