Skip to content

Instantly share code, notes, and snippets.

@sorashido
Last active June 22, 2018 08:01
Show Gist options
  • Save sorashido/b13c7d6cc5978c8880d6c852585bc573 to your computer and use it in GitHub Desktop.
Save sorashido/b13c7d6cc5978c8880d6c852585bc573 to your computer and use it in GitHub Desktop.
from TwitterAPI import TwitterAPI, TwitterPager
import csv
SCREEN_NAME = 'McDonaldsJapan'
CONSUMER_KEY = 'xxx'
CONSUMER_SECRET = 'xxxxxx'
api = TwitterAPI(CONSUMER_KEY,
CONSUMER_SECRET,
auth_type='oAuth2')
pager = TwitterPager(api,
'statuses/user_timeline',
{'screen_name':SCREEN_NAME})
csvFile = open('2018.csv', 'a')
csvWriter = csv.writer(csvFile)
count = 0
for item in pager.get_iterator():
print(item)
csvWriter.writerow([item['created_at'],item['user']['screen_name'], item['text'] if 'text' in item else item])
count += 1
if count > 2:
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment