Last active
August 29, 2015 13:56
-
-
Save utgwkk/8876833 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import tweepy | |
import re | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
me = 'YOUR_SCREEN_NAME' | |
class Listener(tweepy.StreamListener): | |
def on_status(self,s): | |
try: | |
if 'update_name' in s.text and not 'RT' in s.text: | |
m = re.match(r'@%s update_name (.+)'%me,s.text) | |
if m: | |
api.update_profile(name=m.group(1)) | |
api.update_status(u'@%s %sに改名しました'%(s.author.screen_name,m.group(1)),s.id) | |
print 'Updated.' | |
except Exception,e: | |
print >> sys.stderr, 'Exception: ', e | |
finally: | |
return True | |
if __name__ == '__main__': | |
auth = tweepy.OAuthHandler(CONSUMER_KEY,CONSUMER_SECRET) | |
print auth.get_authorization_url() | |
verifier = raw_input('PIN: ').rstrip() | |
try: | |
auth.get_access_token(verifier) | |
auth.set_access_token(auth.access_token.key, auth.access_token.secret) | |
api = tweepy.API(auth) | |
me = api.me().screen_name | |
except tweepy.TweepError: | |
pass | |
else: | |
stream = tweepy.Stream(auth, Listener()) | |
stream.userstream() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment