Last active
October 14, 2015 05:37
-
-
Save Momijinn/689fbb201bfc6a60db75 to your computer and use it in GitHub Desktop.
pythonでtwitterをするときのコマンド
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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
''' | |
Create date: 2015/10/12 | |
implementafor: K.Takano | |
HP: http://miyakawamomiji.blogspot.jp/ | |
''' | |
from twitter import * | |
#あなたのツイッターIDを記入 | |
your_twitter_id = "Your_twitterID" #(ex)momijinn_aka | |
#OAuth ToolからもらえるKeyなどを入力 | |
consumerKey = "Consumer key" | |
consumerSecret = "Consumer secret" | |
accessToken = "Access token" | |
accessSecret = "Access token secret" | |
t = Twitter( | |
auth=OAuth(accessToken, accessSecret, consumerKey, consumerSecret)) | |
#ツイート | |
''' | |
t.statuses.update(status='こんばんわ') | |
''' | |
#ホームタイムラインの取得 | |
''' | |
timeline = t.statuses.home_timeline() #(count=5)にすると5行取得可 | |
#print(timeline[0]['user']['screen_name']) | |
for x in timeline: | |
print(x['user']['name'] + ":@"+x['user']['screen_name']) #ユーザーネーム | |
print(x['text']) #ツイート内容 | |
print("-------------------------------------------------------------") | |
pass | |
''' | |
#誰かのユーザータイムラインを入手 | |
''' | |
usertimeline = t.statuses.user_timeline(screen_name=your_twitter_id) | |
print(usertimeline[0]) | |
''' | |
#ダイレクトメッセージを送る | |
''' | |
t.direct_messages.new(user=your_twitter_id,text="Test Direct Massage") | |
''' | |
#ツイートの検索 | |
''' | |
search = t.search.tweets(q='test', locale='ja', count=100, include_entities=False) | |
for x in search[ 'statuses']: | |
print('@'+ x['user']['screen_name']) | |
print(x['created_at']) | |
print(x['text']) | |
print('-------------------------------------') | |
pass | |
''' | |
#お気に入りしたリストを表示 | |
''' | |
favorites = t.favorites.list() #(user=your_twitter_id)で特定の人 | |
print(favorites) | |
''' | |
#フォローしてる人のIDを列挙 | |
''' | |
friends = t.friends.list(screen_name=your_twitter_id) | |
for x in friends['users']: | |
print(x['screen_name']) | |
pass | |
''' | |
#フォロワーのID列挙 | |
''' | |
followers = t.followers.list(screen_name=your_twitter_id, count=50) | |
for x in followers['users']: | |
print('@' + x['screen_name']) | |
print('tweet:' + str(x['statuses_count'])) | |
print('follows:' + str(x['friends_count'])) | |
print('followers:' + str(x['followers_count'])) | |
print('following:' + str(x['following'])) | |
print('---------------------------------------------------') | |
pass | |
''' | |
#フォローする | |
'''' | |
t.friendships.create(screen_name=create_twitter_id)#create_twitter_id=フォローするTwitterID | |
''' | |
#フォロー解除 | |
''' | |
t.friendships.destroy(screen_name=destroy_twitter_id)#destroy_twitter_id=フォロー解除するTwitterID | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sixohsix氏のTwitterパッケージで使えそうなものをとりあえず列挙したもの
他にも使えるコマンドがあるのでTwitterAPIを参照 → https://dev.twitter.com/rest/public
sixohsix氏のTwitterパッケージ
https://github.com/sixohsix/twitter