今は反省している。 (これをcrontabで定期的に走らせたりすると・・・ゴホゴホ)
勢いでやったからよく覚えていないがこれを使ったっぽい。
#!/Library/Frameworks/Python.framework/Versions/7.2/bin/python # -*- coding: utf-8 -*- SCRIPT_TYPE="InstrumentalityOfMankind" SCRIPT_SHELL="python" SCRIPT_NAME="" SCRIPT_HELP_ARG="" SCRIPT_HELP_SENTENCE="" SCRIPT_NUM_ARG=0 SCRIPT_VERSION=1.0 ###IMPORT### import sys import tweepy import random import time ###HELP### if len(sys.argv[1:])!=SCRIPT_NUM_ARG: print 'Name: '+SCRIPT_NAME print 'Arguments: '+SCRIPT_HELP_ARG print 'Explanation: '+SCRIPT_HELP_SENTENCE sys.exit() ###MAIN### CONSUMER_KEY = '' CONSUMER_SECRET = '' logfile="temp.log" ###ふぁんくしょん### def Tweets(ack, acs, text) : CONSUMER_KEY = '' CONSUMER_SECRET = '' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ack, acs) api = tweepy.API(auth, api_root='/1.1') api.update_status(text) for p in tweepy.Cursor(api.user_timeline).items(1): lastid=p.id print text del api return lastid def Tweets_as_A(text) : ACCESS_KEY1 = '' ACCESS_SECRET1 = '' return Tweets(ACCESS_KEY1, ACCESS_SECRET1, text) def Tweets_as_B(text) : ACCESS_KEY2 = '' ACCESS_SECRET2 = '' return Tweets(ACCESS_KEY2, ACCESS_SECRET2, text) def Reply(ack, acs, text, lastid, to_usr) : CONSUMER_KEY = '' CONSUMER_SECRET = '' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ack, acs) api = tweepy.API(auth, api_root='/1.1') name_to_reply = to_usr status_id_to_reply = lastid text2 = u'@%s %s' % (name_to_reply, text) api.update_status(text2, in_reply_to_status_id = status_id_to_reply) print text2 for p in tweepy.Cursor(api.user_timeline).items(1): a=p.id del api return a def Reply_as_A(text,lastid) : ACCESS_KEY1 = '' ACCESS_SECRET1 = '' return Reply(ACCESS_KEY1, ACCESS_SECRET1, text, lastid, "B") def Reply_as_B(text, lastid) : ACCESS_KEY2 = '' ACCESS_SECRET2 = '' return Reply(ACCESS_KEY2, ACCESS_SECRET2, text, lastid, "A") ####おだいけってい### num_wadai=2 f1=open(logfile,"r") old_nums=[] for line in f1: old_nums.append(line) f1.close() prev_num=int(old_nums[-1]) num_now=random.randint(1, num_wadai) while prev_num == num_now : num_now=random.randint(1, num_wadai) print num_now, prev_num f1=open(logfile,"w") old_nums.append(str(num_now)+"\n") f1.writelines(old_nums) f1.close() ####おしゃべり##### if num_now==1 : text=u"はーちみつ!" sid=Tweets_as_A(text) text=u"レモン!" sid=Reply_as_B(text, sid) elif num_now==2 : text=u"レモンはー!" sid=Tweets_as_B(text) text=u"ハチミツ!" sid=Reply_as_A(text, sid) text=u"なんでやねん!" sid=Reply_as_B(text, sid)