Last active
August 29, 2015 14:21
-
-
Save erickgnavar/15404c12635b3aab8a5c to your computer and use it in GitHub Desktop.
Twitter mongo example
This file contains 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
pymongo | |
twython |
This file contains 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
# coding: utf-8 | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
ACESS_TOKEN = '' | |
ACCESS_TOKEN_SECRET = '' | |
from twython import TwythonStreamer | |
from pymongo import MongoClient | |
db = MongoClient('localhost').twitter | |
class MyStreamer(TwythonStreamer): | |
def on_success(self, data): | |
db.my_db.insert(data) | |
def on_error(self, status_code, data): | |
print status_code | |
stream = MyStreamer(CONSUMER_KEY, CONSUMER_SECRET, | |
ACESS_TOKEN, ACCESS_TOKEN_SECRET) | |
stream.statuses.filter(track='#hashtag') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment