Exemple #1
0
def getMenu(today):
    day = today.weekday()
    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()
    ignore_hashtags = lambda post: " ".join(word.lower()
                                            for word in post.split()
                                            if word[0] != "#")
    daily_menu_filter = lambda post: is_today(post['created_time']) \
                            and "menü" in post['message'].lower()
    weekly_menu_filter = lambda post: is_this_week(post['created_time']) \
                            and days_lower[day] in ignore_hashtags(post['message'])
    weekly_menu = get_filtered_fb_post(FB_ID, weekly_menu_filter)
    if weekly_menu:
        menu = pattern_slice(
            weekly_menu.splitlines(), [days_lower[day]],
            days_lower + ["sütiket", "#", "jó étvágyat", "mai menü"])
    else:
        menu_post = get_filtered_fb_post(FB_ID, daily_menu_filter).splitlines()
        menu = []
        for i, line in enumerate(menu_post):
            if "A:" in line:
                menu = list((menu_post[i - 1], menu_post[i], menu_post[i + 1]))
                break
    return menu
Exemple #2
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 + ["desszert"], inclusive=False)
    menu = skip_empty_lines(menu)
    return list(menu)
Exemple #3
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
Exemple #4
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))
Exemple #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
Exemple #6
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 "jelmagyarázat" 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=False)

    return menu
Exemple #7
0
def get_menu(today):
    dom = get_dom(URL, force_utf8=True)
    menudate = ''.join(dom.xpath('/html/body//div[@id="datum"]//text()'))
    start_month, start_day, *_ = split(" |-", menudate)
    menu_start_date = date(today.year, parse_hungarian_month(start_month), int(start_day))
    if menu_start_date <= today.date() < menu_start_date + timedelta(days=7):
        menu = dom.xpath('/html/body//div[preceding-sibling::div[@id="datum"]]//article[@class="lmenu"]//text()')
        menu = pattern_slice(menu, [days_lower[today.weekday()]], days_lower)
    else:
        menu = []
    return menu
Exemple #8
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 = menu.replace("•", "\n")
    menu = pattern_slice(menu.splitlines(), [days_lower[today.weekday()]],
                         days_lower +
                         ["wolt", "ez is budai", "nyitva", "rendelj"],
                         inclusive=True)

    return menu
Exemple #9
0
def get_menu(today):
    dom = get_dom(URL)
    menu_week_number = dom.xpath("/html/body//div[@class='itemBody']//h2[@class='itemTitle']//text()")
    menu_week_number =  ''.join(char for char  in ''.join(menu_week_number) if char.isnumeric())
    _, current_week_number, _ = today.date().isocalendar()

    if menu_week_number == str(current_week_number):
        week_menu = dom.xpath("/html/body//div[@class='itemBody']//div[@class='heti-menu']//text()")
        lower = lambda line: remove_accents(line).lower()
        menu = pattern_slice(week_menu, [days_lower_ascii[today.weekday()]], days_lower_ascii, modifier=lower)
    else:
        menu = []

    return menu
Exemple #10
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 \
        any(word in post['message'].lower() for word in ["lunch menü ", "business lunch", "előételek", "déli menü", "heti menü", "menünk"])
    menu = get_filtered_fb_post(FB_ID, menu_filter)
    drop_words = [
        "előételek", "főételek", "desszer", "étvágy", "menü", "lunch",
        str(today.year)
    ]
    menu = skip_empty_lines(
        filter(lambda l: not any(word in l.lower() for word in drop_words),
               menu.splitlines()))
    menu = pattern_slice(menu, [""], ["---", "broth", "soup"], inclusive=True)

    return list(menu)
Exemple #11
0
def get_menu(today):
    dom = get_dom(URL)
    page = dom.xpath("/html/body//div[@id='heti-men-page']//text()")
    looks_like_a_date = lambda text: text.count(".") > 2 and str(today.year
                                                                 ) in text
    date = next(filter(looks_like_a_date, page))
    date = datetime.strptime(date.split("-")[0].strip(" ."), "%Y.%m.%d")

    if date <= today < date + timedelta(days=6):
        menu = page
    else:
        menu = []

    menu = pattern_slice(menu, ["levesek"],
                         ["étlap", "function", "getElementById"])
    return menu
Exemple #12
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
Exemple #13
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()
                               and "asztalfoglalás" not in post['message'].lower()) \
                               or ("menü" in post['message'].lower()
                                    and is_today(post['created_time'])
                                    and "asztalfoglalás" not in post['message'].lower())

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

    return list(skip_empty_lines(menu))
Exemple #14
0
def get_menu(today):
    fbfilter = lambda post: fb_filter(post, today)
    menu = get_filtered_fb_post(FB_ID, fbfilter)
    menu = pattern_slice(menu.splitlines(), ["holnapi"], ["tomorrow"])
    return menu