Advertisement
Guest User

Untitled

a guest
Jan 7th, 2012
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3.  
  4. import sys, tweepy
  5. from couchdb import Server
  6. from pit import Pit
  7. try:
  8. import simplejson as json
  9. except ImportError:
  10. import json
  11.  
  12. couch_server = Server("http://127.0.0.1:5984/")
  13. couch_db = couch_server.create('twitter')
  14.  
  15. class StreamListener(tweepy.StreamListener):
  16. count = 0
  17. statuses = []
  18.  
  19. def on_data(self, data):
  20. self.statuses.append(json.loads(data))
  21. self.count += 1
  22. if 100 < self.count:
  23. couch_db.update(self.statuses)
  24. self.statuses = []
  25. self.count = 0
  26.  
  27. def main():
  28. conf = Pit.get('twitter.com')
  29. user = conf['username']
  30. passwd = conf['password']
  31. stream = tweepy.Stream(user, passwd, StreamListener())
  32. stream.sample()
  33.  
  34. if __name__ == "__main__":
  35. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement