-
-
Save CleitonDeLima/a8552df5b71893a0081244f7e0c109f1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CONSUMER_KEY= | |
CONSUMER_SECRET= | |
ACCESS_TOKEN= | |
ACCESS_SECRET= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python-decouple==3.1 | |
tweepy==3.6.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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