【Python】tweepyを使って自分のツイートを取得してCSVファイルに保存する方法
This file contains 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
# codin: utf-8 | |
import tweepy | |
import csv | |
def oauth(): | |
consumer_key = "consumer_key" | |
consumer_secret = "consumer_secret" | |
access_key = "access_key" | |
access_secret = "access_secret" | |
auth = tweepy.OAuthHandler(consumer_key, consumer_secret) | |
auth.set_access_token(access_key, access_secret) | |
return auth | |
if __name__ == "__main__": | |
api = tweepy.API(oauth()) | |
with open("tweet.csv", "a") as f: | |
writer = csv.writer(f, lineterminator="\n") | |
for status in tweepy.Cursor(api.user_timeline).items(): | |
writer.writerow([status.text.encode('utf-8'), status.created_at]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment