Skip to content

Instantly share code, notes, and snippets.

@edy4c7
Created March 10, 2016 13:22
Show Gist options
  • Select an option

  • Save edy4c7/c38193558d010072b63f to your computer and use it in GitHub Desktop.

Select an option

Save edy4c7/c38193558d010072b63f to your computer and use it in GitHub Desktop.
お気に入り(Like)保存するやつ
# -*- coding: utf-8 -*-
import json
import tweepy
from datetime import datetime
def main():
#Twitter認証
consumer_key = ''
consumer_secret = ''
access_token_key = ''
access_token_secret = ''
auth = tweepy.OAuthHandler(consumer_key,consumer_secret)
auth.set_access_token(access_token_key,access_token_secret)
api = tweepy.API(auth)
favs = []
#APIリミットの限界までFavを最新から取得
try:
for item in tweepy.Cursor(api.favorites, count = 200).items():
favs.append(item._json)
except Exception as ex:
print(type(ex))
print(ex)
#ファイル出力
output_name = 'output-{0:%Y%m%d%H%M%S}.json'.format(datetime.now())
try:
with open(output_name, 'w') as ff:
json.dump(favs, ff, sort_keys = True, ensure_ascii = False, indent = 4)
except Exception as ex:
print(type(ex))
print(ex)
print(len(favs))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment