kompot.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:ebedke 作者: ijanos 项目源码 文件源码
def getMenu(today):
    menu = ''
    try:
        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_post = dropwhile(lambda line: days_lower[day] not in line.lower(), skip_empty_lines(weekly_menu.split('\n')))
        else:
            menu_post = get_filtered_fb_post(FB_ID, daily_menu_filter).split('\n')

        menu_post = list(menu_post)
        for i, line in enumerate(menu_post):
            if "A:" in line:
                menu = "<br>".join((menu_post[i-1], menu_post[i], menu_post[i+1]))
                break
    except:
        pass

    return {
        'name': 'Kompót',
        'url': FB_PAGE,
        'menu': menu
    }
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号