Commit 8e181580 authored by Aaron1011's avatar Aaron1011
Browse files

Merge pull request #350 from Aaron1011/sitestream

Added sitestream endpoint
parents 7b61a6b7 55a774d9
...@@ -45,15 +45,23 @@ class TweepyStreamTests(unittest.TestCase): ...@@ -45,15 +45,23 @@ class TweepyStreamTests(unittest.TestCase):
def tearDown(self): def tearDown(self):
self.stream.disconnect() self.stream.disconnect()
def on_connect():
API(self.auth).update_status(mock_tweet())
def test_userstream(self): def test_userstream(self):
# Generate random tweet which should show up in the stream. # Generate random tweet which should show up in the stream.
def on_connect():
API(self.auth).update_status(mock_tweet()) self.listener.connect_cb = self.on_connect
self.listener.connect_cb = on_connect
self.listener.status_stop_count = 1 self.listener.status_stop_count = 1
self.stream.userstream() self.stream.userstream()
self.assertEqual(self.listener.status_count, 1) self.assertEqual(self.listener.status_count, 1)
def test_sitestream(self):
self.listener.connect_cb = self.on_connect
self.listener.status_stop_count = 1
self.sitestream(follow=[self.auth.get_username()])
self.assertEqual(self.listener.status_count, 1)
def test_userstream_with_params(self): def test_userstream_with_params(self):
# Generate random tweet which should show up in the stream. # Generate random tweet which should show up in the stream.
......
...@@ -313,6 +313,22 @@ class Stream(object): ...@@ -313,6 +313,22 @@ class Stream(object):
self.host = 'stream.twitter.com' self.host = 'stream.twitter.com'
self._start(async) self._start(async)
def sitestream(self, follow, stall_warnings=False, with_='user', replies=False, async=False):
self.parameters = {}
if self.running:
raise TweepError('Stream object already connected!')
self.url = '/%s/site.json' % STREAM_VERSION
self.parameters['follow'] = ','.join(map(str, follow))
self.parameters['delimited'] = 'length'
if stall_warnings:
self.parameters['stall_warnings'] = stall_warnings
if with_:
self.parameters['with'] = with_
if replies:
self.parameters['replies'] = replies
self.body = urlencode_noplus(self.parameters)
self._start(async)
def disconnect(self): def disconnect(self):
if self.running is False: if self.running is False:
return return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment