add_page.py 文件源码

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

项目:facebook-scrapper 作者: avihai123 项目源码 文件源码
def add_page(arg):
    """
    add specific information from facebook page to DB

    connecting facebook api and request selected fields.
    :param arg: page name, id or full url
    """
    if '/' in arg:
        fb_url = arg.split('/')[-1]
    else:
        fb_url = arg
    try:
        new_page = graph.get_object(REQUEST_FORMAT.format(fb_url, FIELDS_FORMAT))
    except facebook.GraphAPIError:
        print('Not a page')
        exit()

    # relpace cover with cover link
    new_page['cover'] = new_page['cover']['source'] if 'cover' in new_page.keys() else 'default'
    # add field values to database
    upsert(pages, new_page)
    print(SUCCESS_ADD_MSG.format(**new_page))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号