Skip to content

Instantly share code, notes, and snippets.

@en0l1c
Forked from Florents-Tselai/foties_tweets.py
Created July 30, 2018 06:28
Show Gist options
  • Save en0l1c/d14bc13ef15276bbdb23fd98f5219810 to your computer and use it in GitHub Desktop.
Save en0l1c/d14bc13ef15276bbdb23fd98f5219810 to your computer and use it in GitHub Desktop.
Script that searches tweets written in Greek and containing specific hashtags relevant to the recent wildfires in Greece. Also outputs twitter profiles created during the last few days just to tweet those tweets [Info & context here: https://www.facebook.com/f.tselai/posts/1981587568532277 ]
import tweepy
from datetime import datetime
auth = tweepy.OAuthHandler('CONSUMER_KEY', 'CONSUMER_SECRET')
auth.set_access_token('ACCESS_TOKEN', 'ACCESS_SECRET')
api = tweepy.API(auth, wait_on_rate_limit=True)
def parse_ts(ts):
return datetime.strptime(ts,'%a %b %d %H:%M:%S +0000 %Y')
tweets = []
recent_profiles = {} # created after July 23th 2018
for tweet in tweepy.Cursor(api.search,
q="#skai_xeftiles OR #skai_kseftiles OR #nd_xeftiles OR #nd_kseftiles OR #skaNDala",
count=1000,
lang="el",
since="2018-07-20"
).items():
tweet_data = (tweet._json['user']['screen_name'], tweet._json['user']['created_at'], tweet.text, tweet.created_at, tweet)
tweets.append(tweet)
if parse_ts(tweet._json['user']['created_at']) >= datetime(2018, 7, 23):
recent_profiles[tweet._json['user']['screen_name']] = tweet._json['user']['created_at']
if len(tweets) % 500 == 0:
print("%d tweets" % len(tweets))
print("%d recent profiles" % len(recent_profiles))
for screen_name, created_at in recent_profiles.items():
print((created_at, 'https://twitter.com/' + screen_name))
import pytz
for screen_name, created_at in recent_profiles.items():
print(('https://twitter.com/' + screen_name, parse_ts(created_at).replace(tzinfo=pytz.timezone('Europe/Athens')).isoformat()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment