Skip to content

Instantly share code, notes, and snippets.

@onurmatik
Last active December 14, 2016 08:49
Show Gist options
  • Save onurmatik/4a0229ae70f0e3fc83a5e2a431059548 to your computer and use it in GitHub Desktop.
Save onurmatik/4a0229ae70f0e3fc83a5e2a431059548 to your computer and use it in GitHub Desktop.
#encoding:utf-8
from datetime import datetime, timedelta
import unicodecsv
from delorean import parse
client = UserClient(
CONSUMER_KEY,
CONSUMER_SECRET,
ACCESS_TOKEN,
ACCESS_TOKEN_SECRET,
)
last_id = None
day = datetime.today()
f = open('tweets-%s.csv' % day.strftime('%Y-%m-%d'), 'w')
w = unicodecsv.writer(f, encoding='utf-8')
while True:
response = client.api.search.tweets.get(
q='#multeciler',
until=day.strftime('%Y-%m-%d'),
include_entities=False,
count=100,
max_id=last_id and last_id-1 or None,
)
tweets = response.data['statuses']
for tweet in tweets:
tweet_time = parse(tweet['created_at']).datetime.replace(tzinfo=None)
if tweet_time > day:
break
w.writerow((
tweet['id'],
tweet['screen_name'],
tweet['text'],
tweet_time.strftime('%Y-%m-%d %H:%M:%S'),
))
last_id = tweet['id']
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment