Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/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