Skip to content

Commit

Permalink
added Finn In menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Noxet committed Oct 16, 2016
1 parent ee2f5c6 commit ca1d0a2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
8 changes: 7 additions & 1 deletion geoffrey.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# TODO: load the classes dynamically
from menus.mop import MOP
from menus.finnut import FinnUt
from menus.finnin import FinnIn

with open('slack_config.yaml', 'r') as stream:
try:
Expand Down Expand Up @@ -55,7 +56,12 @@ def post_lunch(dow, channel):
for dish in dishes:
resp += '- \t%s\n' % dish

resp += '\nYours Truely,\nGeoffrey'
dishes = FinnIn().get_day(dow)
resp += '*%s*\n' % FinnIn()
for dish in dishes:
resp += '- \t%s\n' % dish

resp += '\n_Yours Truely_,\nGeoffrey'
#print (resp)
slackc.api_call('chat.postMessage', channel=channel, text=resp, as_user=True)

Expand Down
53 changes: 53 additions & 0 deletions menus/finnin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

import requests
from bs4 import BeautifulSoup

from menus.menu import Menu

class FinnIn(Menu):

def __init__(self):
self.url = 'http://www.finninn.se/lunch-meny/'
self.menu = {}
# swedish day of week names
self.dow = {0: 'måndag', 1: 'tisdag', 2: 'onsdag', 3: 'torsdag', 4: 'fredag'}

def __repr__(self):
return "Finn In"

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('ul', {'class': 'menu-items'})
for li in menu_list.find_all('li', recursive=False):
# get the day of week
weekday = li.find('div', {'class': 'grid2column'}).text.strip().lower()
# get the dishes of the day
dishes = li.find('div', {'class': 'item-description-menu'}).text

# add the list of dishes to the menu
self.menu[weekday] = dishes.strip().split('\n')

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]

0 comments on commit ca1d0a2

Please sign in to comment.