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)
评论列表
文章目录