Created
January 10, 2010 14:26
-
-
Save riaf/273537 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import sys, tweepy | |
from couchdb import Server | |
from pit import Pit | |
try: | |
import simplejson as json | |
except ImportError: | |
import json | |
couch_server = Server("http://127.0.0.1:5984/") | |
couch_db = couch_server.create('twitter') | |
class StreamListener(tweepy.StreamListener): | |
count = 0 | |
statuses = [] | |
def on_data(self, data): | |
self.statuses.append(json.loads(data)) | |
self.count += 1 | |
if 100 < self.count: | |
couch_db.update(self.statuses) | |
self.statuses = [] | |
self.count = 0 | |
def main(): | |
conf = Pit.get('twitter.com') | |
user = conf['username'] | |
passwd = conf['password'] | |
stream = tweepy.Stream(user, passwd, StreamListener()) | |
stream.sample() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment