Skip to content

Instantly share code, notes, and snippets.

@CleitonDeLima
Last active March 25, 2018 22:34
Show Gist options
  • Save CleitonDeLima/a8552df5b71893a0081244f7e0c109f1 to your computer and use it in GitHub Desktop.
Save CleitonDeLima/a8552df5b71893a0081244f7e0c109f1 to your computer and use it in GitHub Desktop.
CONSUMER_KEY=
CONSUMER_SECRET=
ACCESS_TOKEN=
ACCESS_SECRET=
eleições2018
bolsonaro
EscolaSemPartido
doutrinacaoideologica
nordeste de merda
vagabunda
puta
piranha
gay
viado
bicha
bichinha
boiola
biba
baitola
baianagem
negragem
retardado
bugre
nego
preto fedido
nego viado
velho idiota
cachaceiro
viadinho
sapatão
cafetão
seu merda
otário
vacilão
humor negro
python-decouple==3.1
tweepy==3.6.0
from datetime import datetime
import tweepy
from decouple import config
from tweepy import OAuthHandler
from tweepy import Stream
from tweepy.streaming import StreamListener
CONSUMER_KEY = config('CONSUMER_KEY')
CONSUMER_SECRET = config('CONSUMER_SECRET')
ACCESS_TOKEN = config('ACCESS_TOKEN')
ACCESS_SECRET = config('ACCESS_SECRET')
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_SECRET)
api = tweepy.API(auth)
filter_lines = open('filters.txt', 'r').readlines()
filters = [f.strip() for f in filter_lines]
class MyListener(StreamListener):
count = 0
def on_data(self, data):
now = datetime.now()
date_str = now.strftime('%d-%m-%Y')
try:
with open(f'data/tweets-{date_str}.json', 'a') as f:
f.write(data)
self.count += 1
print(f'{self.count} tweets saved!')
return True
except BaseException as e:
print(f"Error on_data: {e}")
return True
def on_error(self, status):
print(status)
return True
twitter_stream = Stream(auth, MyListener())
twitter_stream.filter(track=filters)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment