home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2011 October / maximum-cd-2011-10.iso / DiscContents / digsby_setup.exe / lib / plugins / twitter / twitterstream.pyo (.txt) < prev   
Encoding:
Python Compiled Bytecode  |  2011-06-22  |  2.3 KB  |  44 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.6)
  3.  
  4. import netextensions
  5. import common.asynchttp as asynchttp
  6. from common import netcall
  7. from util.primitives.funcs import Delegate
  8. from logging import getLogger
  9. log = getLogger('twstrm')
  10.  
  11. class TwitterStream(object):
  12.     
  13.     def __init__(self, username, password, follow_ids):
  14.         self.follow_ids = follow_ids
  15.         self.httpmaster = asynchttp.HttpMaster()
  16.         uris = [
  17.             'stream.twitter.com',
  18.             'twitter.com']
  19.         realm = 'Firehose'
  20.         self.httpmaster.add_password(realm, uris, username, password)
  21.         self.post_data = 'follow=' + ','.join((lambda .0: for i in .0:
  22. str(i))(follow_ids))
  23.         self.on_tweet = Delegate()
  24.  
  25.     
  26.     def start(self):
  27.         url = 'http://stream.twitter.com/1/statuses/filter.json'
  28.         req = asynchttp.HTTPRequest.make_request(url, data = self.post_data, method = 'POST', accumulate_body = False)
  29.         req.bind_event('on_chunk', self._on_chunk)
  30.         log.info('starting twitter stream, following %d people', len(self.follow_ids))
  31.         (None, netcall)((lambda : self.httpmaster.request(req)))
  32.  
  33.     
  34.     def _on_chunk(self, chunk):
  35.         if len(chunk) < 5 and not chunk.strip():
  36.             return None
  37.         self.on_tweet(chunk)
  38.  
  39.     
  40.     def stop(self):
  41.         log.warning('TODO: TwitterStream.stop')
  42.  
  43.  
  44.