def reply_to_tweets(): print('retrieving and replying to tweets...', flush=True) # id last seen testing : 1112619279025725441 1124521036538568704 url = "http://188.166.216.148:4545/" response = requests.request("GET", url) last_seen_id = response.text mentions = api.mentions_timeline( last_seen_id, tweet_mode='extended') print('last seen id : ', last_seen_id) # print(mentions) for mention in reversed(mentions): #supaya membaca perulangannya terbalik.. #biasanya list mention di timline dibaca dari yg terakhir dahulu, supaya terurut, maka dibalik print(str(mention.id) + ' - ' + mention.full_text + ' - ' +str(mention.in_reply_to_screen_name), flush=True) last_seen_id = str(mention.id) store_last_seen_id(last_seen_id) tweet = mention.full_text tlow = tweet.lower() # print(tlow) city = re.findall(r"#(\w+)", tlow) translate = Translate() ans = translate.kamusDaerah(city) print(ans) # if '#hai' in mention.full_text.lower(): if ans != "no" and mention.in_reply_to_screen_name != 'cuaca_kita': print('menemukan tweet yang harus dibalas!', flush=True)
def reply_to_tweets(): print('retrieving and replying to tweets...', flush=True) # id last seen testing : 1112619279025725441 url = "http://188.166.216.148:4545/" response = requests.request("GET", url) last_seen_id = response.text mentions = api.mentions_timeline(last_seen_id, tweet_mode='extended') print('last seen id : ', last_seen_id) for mention in reversed( mentions): #supaya membaca perulangannya terbalik.. #biasanya list mention di timline dibaca dari yg terakhir dahulu, supaya terurut, maka dibalik print(str(mention.id) + ' - ' + mention.full_text, flush=True) last_seen_id = str(mention.id) store_last_seen_id(last_seen_id) tweet = mention.full_text tlow = tweet.lower() city = re.findall(r"#(\w+)", tlow) translate = Translate() ans = translate.kamusDaerah(city) print(ans) # if '#hai' in mention.full_text.lower(): if ans != "no": print('menemukan tweet yang harus dibalas!', flush=True) text_gen = Text_generator() data = text_gen.getCData(ans) sentence = text_gen.generator(data) print('respond tweet...', flush=True) api.update_status( 'Hai! @' + mention.user.screen_name + " " + sentence, mention.id) elif city != []: api.update_status( 'Hai! @' + mention.user.screen_name + " sayang sekali Cuki hanya dibuat untuk kamu yang ingin tau prakiraan cuaca di Indonesia saja\n\nAyo coba yang lain", mention.id)