# https://marcobonzanini.com/2015/03/02/mining-twitter-data-with-python-part-1/comment-page-1/
# conda install -c conda-forge tweepy
import tweepy
from tweepy import OAuthHandler
import json

# twitter 계정이 있다면 앱을 만들어서 등록
# 그렇지 않을 시에는 데이터베이스에 있는 정보 등록
consumer_key = 'xx'
consumer_secret = 'xx'
access_token = 'xx'
access_secret = 'xx'

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)
api = tweepy.API(auth)

def toJSON(tweet):
    print(json.dumps(tweet, ensure_ascii=False))

# 팔로잉 친구 목록
for friend in tweepy.Cursor(api.friends).items():
    toJSON(friend._json)
# 트윗 및 답글 목록
for tweet in tweepy.Cursor(api.user_timeline).items():
    toJSON(tweet._json)