Esempio n. 1
0
def get_menu(today):
    dom = get_dom(URL_ROOT)
    menu = dom.xpath("/html/body//article//text()")
    menu = pattern_slice(menu, [days_lower[today.weekday()]],
                         days_lower + ['ára', 'előfizetés', 'ajánlat'],
                         inclusive=False)
    return list(skip_empty_lines(menu))
Esempio n. 2
0
def getMenu(today):
    dom = get_dom(URL)
    this_year = today.strftime("%Y")
    menu_date = dom.xpath(
        f"/html/body//span[contains(text(), '{this_year}')]/text()")
    menu_date = menu_date[0].split('-')[0] if len(menu_date) > 0 else -1
    if menu_date is not -1 and dt.strptime(
            menu_date, "%Y.%m.%d").date() > today.date() - timedelta(days=6):
        menu = list(
            skip_empty_lines([
                p.text_content()
                for p in dom.xpath('/html/body//div[@id="comp-jhonyf7y"]//p')
            ]))
        if any(days_lower[today.weekday()] in line for line in menu):
            menu = list(
                pattern_slice(menu, [days_lower[today.weekday()]],
                              days_lower,
                              inclusive=False))
        else:
            menu = list(menu)
        menu = [item.replace('\xa0', ' ') for item in menu]
    else:
        menu = []

    return menu
Esempio n. 3
0
def getMenu(today):
    is_this_week = lambda date: datetime.strptime(
        date, '%Y-%m-%dT%H:%M:%S%z').date() > today.date() - timedelta(days=7)
    menu_filter = lambda post: is_this_week(post['created_time']) and sum(
        day in post['message'].lower() for day in days_lower) >= 2
    menu = get_filtered_fb_post(FB_ID, menu_filter)
    menu = pattern_slice(menu.splitlines(), [days_lower[today.weekday()]],
                         days_lower + ["wolt", "ez is budai", "nyitva"],
                         inclusive=False)
    menu = skip_empty_lines(menu)
    return list(menu)
Esempio n. 4
0
def getMenu(today):
    is_this_week = lambda date: datetime.strptime(
        date, '%Y-%m-%dT%H:%M:%S%z').date() > today.date() - timedelta(days=6)
    menu_filter = lambda post: is_this_week(post['created_time']) and sum(
        day in post['message'].lower() for day in days_lower) >= 2
    menu = get_filtered_fb_post(FB_ID, menu_filter)
    menu = ''.join(char for char in menu if ord(char) < 500)
    menu = pattern_slice(menu.splitlines(), [days_lower[today.weekday()]],
                         days_lower + ["tel:", "797"])

    return list(skip_empty_lines(menu))
Esempio n. 5
0
def get_menu(today):
    is_this_week = lambda date: datetime.strptime(
        date, '%Y-%m-%dT%H:%M:%S%z').date() >= today.date() - timedelta(days=7)
    menu_filter = lambda post: is_this_week(post[
        'created_time']) and days_lower[today.weekday()] in post['message'
                                                                 ].lower()
    menu = get_filtered_fb_post(FB_ID, menu_filter)
    menu = pattern_slice(menu.splitlines(), [days_lower[today.weekday()]],
                         days_lower,
                         inclusive=True)
    menulist = []
    for line in menu:
        line = line.split(":", maxsplit=1)[1] if ':' in line else line
        menulist.append(line)

    return menulist
Esempio n. 6
0
def getMenu(today):
    is_this_week = lambda date: datetime.strptime(
        date, '%Y-%m-%dT%H:%M:%S%z').date() > today.date() - timedelta(days=7)
    is_today = lambda date: datetime.strptime(date, '%Y-%m-%dT%H:%M:%S%z'
                                              ).date() == today.date()

    menu_filter = lambda post: (is_this_week(post['created_time'])
                               and days_lower[today.weekday()] in post['message'].lower()) \
                               or ("menü" in post['message'].lower() and is_today(post['created_time']))

    menu = get_filtered_fb_post(FB_ID, menu_filter)
    menu = pattern_slice(menu.splitlines(),
                         [days_lower[today.weekday()], "mai", "menü"],
                         days_lower + ["ár:"])

    remove_emoji = lambda text: ''.join(char for char in text
                                        if ord(char) < 500)
    menu = [remove_emoji(m) for m in skip_empty_lines(menu)]

    return menu
Esempio n. 7
0
def get_menu(today):
    is_this_week = lambda date: datetime.strptime(
        date, '%Y-%m-%dT%H:%M:%S%z').date() >= today.date() - timedelta(days=7)
    menu_filter = lambda post: is_this_week(post[
        'created_time']) and "heti menü" in post['message'].lower()
    image = get_fb_post_attached_image(FB_ID, menu_filter)
    if image:
        image = Image.open(BytesIO(image)).convert('L')
        f = BytesIO()
        image.save(f, format="png", optimize=True)
        menu = ocr_image(f).splitlines()
        if not menu:
            return []

        menu = pattern_slice(menu, [days_lower[today.weekday()]],
                             days_lower + ['desszert', "890"],
                             inclusive=False)
        menu = list(skip_empty_lines(menu))
    else:
        return []

    return menu