Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python -u
- #-*- coding: utf-8 -*-
- import tweepy, json, pymongo
- #Autenticazione
- from keys import keys
- SCREEN_NAME = keys['screen_name']
- CONSUMER_KEY = keys['consumer_key']
- CONSUMER_SECRET = keys['consumer_secret']
- ACCESS_TOKEN = keys['access_token']
- ACCESS_TOKEN_SECRET = keys['access_token_secret']
- auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
- auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
- api = tweepy.API(auth)
- class CustomStreamListener(tweepy.StreamListener):
- def __init__(self, api):
- self.api = api
- super(tweepy.StreamListener, self).__init__()
- self.db = pymongo.MongoClient().test
- def on_data(self, tweet):
- self.db.europe.insert(json.loads(tweet))
- def on_error(self, status_code):
- return True # Don't kill the stream
- def on_timeout(self):
- return True # Don't kill the stream
- sapi = tweepy.streaming.Stream(auth, CustomStreamListener(api))
- #sapi.filter(track=['#Apple', '#Linux', '#Windows'])
- sapi.filter(locations=[-122.75,36.8,-121.75,37.8])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement