Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@riaf
Created January 10, 2010 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riaf/273537 to your computer and use it in GitHub Desktop.
Save riaf/273537 to your computer and use it in GitHub Desktop.
#!/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