-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from zozs/master
Fix MoP menu (finally). Also add requirements.txt.
- Loading branch information
Showing
4 changed files
with
80 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
UPDATE_TIME: "07:00" | ||
POST_TIME: "11:00" | ||
MENUS: ['mop.MOP', 'finnin.FinnIn', 'finnut.FinnUt', 'avesta.Avesta'] | ||
MENUS: ['mop.MOP', 'finnin.FinnIn', 'finnut.FinnUt', 'avesta.Avesta', 'bryggan.Bryggan'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
|
||
from menus.menu import Menu | ||
|
||
class Bryggan(Menu): | ||
|
||
def __init__(self): | ||
self.url = 'http://www.bryggancafe.se/veckans-lunch/' | ||
self.menu = {} | ||
# swedish day of week names | ||
self.dow = {0: 'Måndag', 1: 'Tisdag', 2: 'Onsdag', 3: 'Torsdag', 4: 'Fredag'} | ||
|
||
def __repr__(self): | ||
return "Bryggan Kök och Café" | ||
|
||
def get_week(self): | ||
""" | ||
Fetches the menu data from the given URL, returns a menu dictionary: | ||
{ | ||
'dayofweek 1': ['dish 1', 'dish 2', ..., 'dish N'], | ||
'dayofweek 2': [ ... ] | ||
} | ||
""" | ||
content = requests.get(self.url) | ||
soup = BeautifulSoup(content.text, 'html.parser') | ||
# menu list | ||
menu_list = soup.find('div', {'class': 'et_pb_promo_description'}) | ||
last_day = None | ||
for p in menu_list.find_all('p', recursive=False): | ||
# get data in each p-tag and ignore em and u tags. | ||
data = p.text.strip() | ||
if len(data) == 0: | ||
continue | ||
|
||
# remove trailing : | ||
if data[-1] == ':': | ||
data = data[:-1] | ||
|
||
# now determine if this is a day-label or menu. | ||
if data in self.dow.values(): | ||
# it was a day label, note it down so we know when we see food | ||
last_day = data | ||
continue | ||
|
||
# if we reach here, it was probably food, anything that starts with | ||
# the string "Dagens:" is considered food. | ||
if last_day and data.startswith('Dagens:'): | ||
self.menu[last_day] = [data[7:].strip()] | ||
last_day = None | ||
|
||
return self.menu | ||
|
||
def get_day(self, dow): | ||
""" | ||
Returns the menu, as a list, of the given day, dow, | ||
where 0 is Monday and 6 is Sunday. | ||
""" | ||
# If the menu hasn't been fetched, do it, it will be cached. | ||
if self.menu == {}: | ||
self.get_week() | ||
|
||
dow_name = self.dow[dow] | ||
if dow_name not in self.menu: | ||
return ['404 - Food not found'] | ||
return self.menu[dow_name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
beautifulsoup4==4.5.1 | ||
bs4==0.0.1 | ||
PyYAML==3.12 | ||
requests==2.12.3 | ||
schedule==0.4.2 | ||
six==1.10.0 | ||
slackclient==1.0.2 | ||
websocket-client==0.39.0 |