twitter_bot.py 文件源码

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

项目:Seq2Seq-chatbot 作者: wataruhashimoto52 项目源码 文件源码
def twitter_bot():
    tf_config = tf.ConfigProto(device_count = {"GPU":0}, log_device_placement = True)

    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    api = tweepy.API(auth)

    with tf.Session(config = tf_config) as sess:
        predictor = predict.EasyPredictor(sess)

        for tweet in tweets():
            status_id, status, bot_flag = tweet
            print("Processing {0}...".format(status.text))
            screen_name = status.author.screen_name
            replies = predictor.predict(status.text)
            if not replies:
                print("no reply")
                continue

            reply_body = replies[0]
            if reply_body is None:
                print("No reply predicted")
            else:
                try:
                    if is_contain(status.text, '??????'):
                        special_reply(api, bot_flag, screen_name, status_id, code = 1)
                    elif is_contain(status.text, '????'):
                        special_reply(api, bot_flag, screen_name, status_id, code = 2)

                    elif is_contain(status.text, '?????'):
                        special_reply(api, bot_flag, screen_name, status_id, code = 3)

                    else:
                        post_reply(api, bot_flag, reply_body, screen_name, status_id)
                except tweepy.TweepError as e:
                    if e.api_code == 187:
                        pass
                    else:
                        raise
            mark_tweet_processed(status_id)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号