예제 #1
0
def Look_for_comments(vendor):
    print(vendor['page_id'])
    graph = GraphAPI(access_token=vendor['access_token'])

    print('Started at {} ....'.format(last_time_function_ran))

    posts = graph.get_connections(
        id=vendor['page_id'], connection_name='posts', fields='updated_time,comments{message,created_time}')
    data = posts['data']
    for post in data:

        post_updated_time = datetime.strptime(
            post['updated_time'], time_format)
        if post_updated_time > last_time_function_ran:
            for comment in post['comments']['data']:
                comment_created_time = datetime.strptime(
                    comment['created_time'], time_format)

                if not check_for_comments(comment['id'], graph, vendor):

                    print('Found Comment!')
                    msg = ask_wit(comment['message'], vendor)
                    if msg:
                        graph.put_comment(object_id=comment['id'],
                                          message=msg)
                        print('Replied to Comment')

    print('...Finished at {}'.format(last_time_function_ran))
예제 #2
0
def comment(facebook_api: facebook.GraphAPI, selection: int) -> None:
    """
    Ask what would you like to comment, comments your response and prints the success of the action
    
    Arguments:
        facebook_api (object) : facebook api graph
        selection (int) : The number of the post the user selected
        
    Returns:
        object - (facebook_api)
    """
    text = input_user_chat("What would you like to comment: ").capitalize()
    facebook_api.put_comment(object_id = selection, message = text)
    print_write_chatbot("It has been successfully commented!\n", color = 'green', attrs_color = ["bold"])
예제 #3
0
def handle_page_feed(data):
    page_id = helper.get_vendor_from_comment(data)
    print(page_id)
    vendor = helper.handle_vendor(page_id)[0]
    graph = GraphAPI(access_token=vendor.page_access_token)
    comment = helper.get_comment_from_feed(data)[0]
    comment_id = helper.get_comment_from_feed(data)[1]
    reply = helper.ask_wit(comment, page_id)
    print(reply)
    if reply:
        print('Replying to Comment')
        graph.put_comment(object_id=comment_id,
                          message=reply)
        print('Replied to Comment')
    return 'Replied to Comment', 200
예제 #4
0
def troll():
    # 최근 실행에서 저장된 feed id
    fid = None
    try:
        f = open('fid.txt', 'r')
        fid = f.read().strip()
        f.close()
    except IOError:
        pass
    print('* Last feed id:', fid)

    graph = GraphAPI(access_token=token)

    print('* Retrieving feeds...')
    feeds = graph.get_connections(id='674366342659988',
                                  connection_name='feed',
                                  fields='message,id')['data']
    print('Done')

    # 받아온 피드 중 가장 최신 피드의 id
    lastest_feed_id = None
    for feed in feeds:
        feed_id = feed['id']
        feed_id = str(feed_id)

        # 받아온 피드 중 가장 최신의 피드 id 저장
        if lastest_feed_id is None:
            lastest_feed_id = feed_id

        # 최근 실행에서 처리한 피드일 경우 종료
        if fid == feed_id:
            break

        print('* Publishing comment on %s...' % feed_id)
        try:
            graph.put_comment(object_id=feed_id, message='일 안함? ㅡㅡ')
        except GraphAPIError as e:
            print(e)
            print('Failed')
            continue
        print('Done')

    # 중복검사를 위해 가장 최신 피드 id 저장
    f = open('fid.txt', 'w')
    f.write(lastest_feed_id)
    f.close()
    print('* Finished.')