Last active
January 1, 2016 07:59
-
-
Save cocodrips/8114963 to your computer and use it in GitHub Desktop.
女子大生にPython講座しました。
This file contains hidden or 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 | |
class Tw: | |
def __init__(self): | |
consumer_key = '' | |
consumer_secret = '' | |
oauth_token_secret = '' | |
oauth_token = '' | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(oauth_token, oauth_token_secret) | |
self.api = tweepy.API(auth_handler=auth, api_root='/1.1', secure=True) | |
# oauth_token発行用 | |
# auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
# print 'Please authorize us: %s' % auth.get_authorization_url() | |
# verifier = raw_input('PIN: ').strip() | |
# print auth.get_access_token(verifier) | |
def user_timeline(self): | |
user_tl = self.api.user_timeline() | |
for tl in user_tl: | |
print '---' | |
print tl.user.screen_name | |
print tl.text | |
print tl.created_at | |
def tweet(self, comment): | |
try: | |
self.api.update_status(comment) | |
except: | |
return False | |
return True | |
if __name__ == '__main__': | |
tw = Tw() | |
while True: | |
command = raw_input() | |
if command == 'tw': | |
print 'input text: ', | |
if tw.tweet(raw_input()): | |
print 'tweet success' | |
if command == 'tl': | |
tw.user_timeline() | |
if command == 'end': | |
break | |
print 'input tw/tl/end' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment