当前位置: 首页>>代码示例>>Python>>正文


Python API.get_channel_history方法代码示例

本文整理汇总了Python中API.get_channel_history方法的典型用法代码示例。如果您正苦于以下问题:Python API.get_channel_history方法的具体用法?Python API.get_channel_history怎么用?Python API.get_channel_history使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在API的用法示例。


在下文中一共展示了API.get_channel_history方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import API [as 别名]
# 或者: from API import get_channel_history [as 别名]
def main():
    # Change the current working directory to the directory the script is located in
    # Don't know why this wasn't the default behavior...
    if len(os.path.dirname(sys.argv[0])) > 0:
        os.chdir(os.path.dirname(sys.argv[0]))

    # dictionary mapping Restaurant to Restaurant
    restaurants = {}
    lunch_channel_json = API.get_channel_history(channel_id=LUNCH_DELIVERY, count=1000)

    id_to_rest_name_dict = json_file_to_dic('rest_ids.json')
    rest_name_to_id_dict = reverse_dic(id_to_rest_name_dict)
    # gather official list of restuarants
    official_rest_name_list = id_to_rest_name_dict.values()

    # Using two separate regexes will help us identify restaurants with 'and' in their name more reliably
    # as we have to split multi-restaurant lists around the word 'and'
    single_rest_regex = re.compile('(?i)^<!group>\s(.*)\sis(?! not)(?:[a-z\s]+)?\shere.?$')
    multiple_rest_regex = re.compile('(?i)^<!group>\s(.*)\sare(?! not)(?:[a-z\s]+)?\shere.?$')
    single_rest_msgs = filter(
        lambda message: single_rest_regex.match(message['text']) is not None,
        lunch_channel_json['messages']
    )
    multiple_rest_msgs = filter(
        lambda message: multiple_rest_regex.match(message['text']) is not None,
        lunch_channel_json['messages']
    )

    for msg in single_rest_msgs:
        rest_name = single_rest_regex.match(msg['text']).group(1).strip()
        rest_name = clean_restaurant_name(rest_name)
        if rest_name in rest_name_to_id_dict:
            rest_id = rest_name_to_id_dict[rest_name]
            add_restaurant(restaurants, rest_name, rest_id, msg)

    for msg in multiple_rest_msgs:
        rest_name_str = multiple_rest_regex.match(msg['text']).group(1)
        # Regex note: & signs come in through the API as &amp;
        rest_name_list = re.split("(?i),\s?(?:and|&amp;)?\s|\s(?:and|&amp;)\s", rest_name_str)
        rest_name_list = clean_rest_list(rest_name_list)
        for rest_name in rest_name_list:
            if rest_name in rest_name_to_id_dict:
                rest_id = rest_name_to_id_dict[rest_name]
                add_restaurant(restaurants, rest_name, rest_id, msg)

    rests_list = restaurants.values()
    rests_list.sort(key=lambda rest: len(rest.unix_timestamps))

    for rest in rests_list:
        print rest

    write_averages_json_file(rests_list)
开发者ID:steenburgh,项目名称:diningin-time-tracker,代码行数:54,代码来源:main.py


注:本文中的API.get_channel_history方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。