Created
October 30, 2016 00:47
-
-
Save tomoima525/79dc7f6f1d2de098454c3f3a139c35c1 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
from requests_oauthlib import OAuth1Session | |
import configparser | |
import json | |
import csv | |
config = configparser.ConfigParser() | |
config.read('config.txt') | |
url = 'https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=tomoaki_imai&count=200&exclude_replies=true' | |
params = {} | |
options = config["keys"] | |
twitter = OAuth1Session(options["ConsumerKey"], options["ConsumerSecret"], options["AccessToken"], options["AccessSecret"]) | |
req = twitter.get(url, params = params) | |
if req.status_code == 200: | |
f = open('sample.csv', 'w') | |
writer = csv.writer(f, lineterminator='\n') | |
timeline = json.loads(req.text) | |
for twt in timeline: | |
str = '{},{},{},{}'.format(twt["retweet_count"], twt["id_str"],twt["text"].replace('\n',''),twt["created_at"]) | |
writer.writerow([str]) | |
else: | |
print ("Error: %d" % req.status_code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment