Skip to content

Instantly share code, notes, and snippets.

@Florents-Tselai
Created July 29, 2018 14:24
Show Gist options
  • Save Florents-Tselai/e8db02a37c8ba7ed373cc757f1d0eaf5 to your computer and use it in GitHub Desktop.
Save Florents-Tselai/e8db02a37c8ba7ed373cc757f1d0eaf5 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