Skip to content

Instantly share code, notes, and snippets.

@Ishibasystems
Created July 15, 2016 16:07
Show Gist options
  • Save Ishibasystems/4c59dc22d380fcdc35a7d8cecc316d20 to your computer and use it in GitHub Desktop.
Save Ishibasystems/4c59dc22d380fcdc35a7d8cecc316d20 to your computer and use it in GitHub Desktop.
TDU_AIリプライ等価コード(10分毎)
#! /usr/local/bin/python3
# -*- coding: utf-8 -*-
import tweepy
from sys import exit
from random import choice
from modules import machine, text
from traceback import format_exc
conf = machine.set()
base = conf['machine']['basedir']
acc_name = 'TDU1AI'
CS_key = conf[acc_name]['app_key']
CS_sec = conf[acc_name]['app_sec']
AC_key = conf[acc_name]['usr_key']
AC_sec = conf[acc_name]['usr_sec']
list_tweetd = base + 'tdu_ai_tweet.log'
def main():
auth = tweepy.OAuthHandler(CS_key, CS_sec)
auth.set_access_token(AC_key, AC_sec)
api = tweepy.API(auth_handler = auth)
position = text.read(list_tweetd)
if len(position):
position = position[0]
else:
position = '1'
try:
statuses = [x for x in api.mentions_timeline(since_id = position)]
except:
print(format_exc() + "API.mentions_timeline Error!")
exit(1)
if int(position) >= statuses[0].id:
exit(0)
position = statuses[0].id_str
statuses.reverse()
for status in statuses:
msg = '愛'
if '蝉' in status.text:
msg = '錆'
if '若さってなん' in status.text:
msg = choice(['振り向かないことさ', '諦めないことさ'])
if '愛ってなん' in status.text:
msg = choice(['ためらわないことさ', '悔やまないことさ'])
try:
api.update_status('@' + status.author.screen_name + ' ' + msg, in_reply_to_status_id_str = status.id_str)
except:
print(format_exc() + "API.update_status Error!")
print('http://twitter.com/' + status.author.screen_name + '/status/' + status.id_str + '\n' + status.text)
exit(1)
text.write(list_tweetd, position)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment