Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/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()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement