import pymongo
import json
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
from modelos_Celular import track_lista
consumer_key = 'just blacked out for security'
consumer_secret = 'just blacked out for security'
access_token = 'just blacked out for security'
access_token_secret = 'just blacked out for security'
class StdOutListener(StreamListener):
def on_data(self, data):
client = pymongo.MongoClient('localhost', 27017)
db = client['twitter_db']
collection = db['twitter_collection']
tweet = json.loads(data)
collection.insert(tweet)
return True
def on_error(self, status):
print(status)
def start_stream():
while True:
try:
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
stream = Stream(auth, l)
stream.filter(track=track_lista)
except:
continue
start_stream()
track_lista = ['iphone 6s',
'iphone 6s plus',
'iphone 6',
'iphone 5s',
'iphone 6 plus',
'iphone 4s',
'iphone 5',
'iphone 5c',
'iphone 4']
after running my application I am getting code 420 times 503