
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 ":waterwave: 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]

@@ -10,16 +10,36 @@
 equests%0A
+import collections%0A%0A
 from bs4
@@ -218,18 +218,45 @@
 .menu = 
-%7B%7D
+collections.defaultdict(list)
 %0A       
@@ -1588,16 +1588,26 @@
 Dagens:%22
+ or %22Veg:%22
  is cons
@@ -1647,16 +1647,17 @@
 day and 
+(
 data.sta
@@ -1674,16 +1674,44 @@
 agens:')
+ or data.startswith('Veg:'))
 :%0A      
@@ -1743,61 +1743,29 @@
 day%5D
- = %5Bdata%5B7:%5D.strip()%5D%0A                last_day = None
+.append(data.strip())
 %0A   

Fix Bryggan to also retrieve vegetarian option.