Created
December 6, 2017 16:37
-
-
Save nomunomu0504/88cda95e697de5f6e89f7aa240a7b255 to your computer and use it in GitHub Desktop.
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
class AutoGood(StreamListener): | |
def on_connect(self): | |
print ('on_connect.') | |
def on_status(self, status): | |
try: | |
# Ubuntuの時は気づかなかったんだけど、Windowsで動作確認してたら | |
# created_atはUTC(世界標準時)で返ってくるので日本時間にするために9時間プラスする。 | |
status.created_at += timedelta(hours=9) | |
# 1tweetの区切り | |
print ('--------------------') | |
print (u"{id}: {screen_name}({name})\n {tweet}".format( | |
id=status.id, | |
screen_name=status.author.screen_name, | |
name=status.author.name, | |
tweet=status.text | |
)) | |
# tweetのjson化したデータを整形する( textベース ) | |
# (unicode表記なし -> 日本語は日本語のまま | |
# result = json.dumps(status._json, ensure_ascii=False, indent=4).encode('utf8') | |
# tweetのjsonを抽出 | |
tweet_json = status._json | |
# 目的のuseridを作成 | |
users = ( | |
# 特定のUserのIDを配列で | |
# r"nomunomu0504", | |
# r"aaaaaaaaa", | |
# ... | |
) | |
for user in users: | |
if tweet_json['user']['screen_name'] == user: | |
# usersにある人のTweetをいいねする | |
favoParams = { | |
'id': status.id, | |
'include_entities': False | |
} | |
# responseによって何かしたいならこっち(reqにレスポンスコードが入る) | |
# req = twitter.post(favoTwiAdress, params=favoParams) | |
# Twitterに投稿 | |
twitter.post(favoTwiAdress, params=favoParams) | |
except Exception as err: | |
print(err) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment