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
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
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))
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 + ["tel:", "797"]) return list(skip_empty_lines(menu))
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", "rendelj"], inclusive=True) return menu
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
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" ] 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)
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
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
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
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))
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
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