From 1cf3d85e81845241d01b1778785e72840e921a38 Mon Sep 17 00:00:00 2001 From: Jorge Varona Date: Tue, 15 Apr 2014 23:01:46 +0000 Subject: [PATCH 1/3] Added [follow] to [Stream] to support Site Streams. Added [stream_info], [add_user], and [remove_user] to [API]. --- tweepy/api.py | 27 +++++++++++++++++++++++++++ tweepy/streaming.py | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/tweepy/api.py b/tweepy/api.py index 74188093d..daacbfe9e 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -675,6 +675,33 @@ def test(self): allowed_param = ['lat', 'long', 'name', 'contained_within'] ) + """ site stream info """ + stream_info = bind_api( + path = '{stream_id}/info.json', + payload_type = 'json', + require_auth = True, + allowed_param = ['stream_id'] + ) + + """ site stream add user """ + add_users = bind_api( + path = '{stream_id}/add_user.json', + payload_type = None, + require_auth = True, + method = 'POST', + allowed_param = ['stream_id','user_id'] + ) + + """ site stream remove user """ + remove_users = bind_api( + path = '{stream_id}/remove_user.json', + payload_type = None, + require_auth = True, + method = 'POST', + allowed_param = ['stream_id','user_id'] + ) + + """ Internal use only """ @staticmethod def _pack_image(filename, max_size): diff --git a/tweepy/streaming.py b/tweepy/streaming.py index f6d37f450..32f515509 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -246,3 +246,22 @@ def disconnect(self): return self.running = False + def follow(self, follow, async=False): + print 'Calling follow for: {0}'.format(follow) + if self.running: + raise TweepError('Stream object already connected!') + + self.scheme = "https" + self.parameters = {} + self.headers['Content-type'] = "application/x-www-form-urlencoded" + self.host = 'sitestream.twitter.com' + self.url = '/%s/site.json?delimited=length' % STREAM_VERSION + + if follow: + self.parameters['follow'] = ','.join(map(str, follow)) + + self.body = urlencode_noplus(self.parameters) + self.parameters['delimited'] = 'length' + self._start(async) + + From fb0debeba2dadfd4ffc599f0ab0dc702d08f391e Mon Sep 17 00:00:00 2001 From: Jorge Varona Date: Tue, 15 Apr 2014 23:01:46 +0000 Subject: [PATCH 2/3] Added [follow] to [Stream] to support Site Streams. Added [stream_info], [add_user], and [remove_user] to [API]. --- tweepy/api.py | 27 +++++++++++++++++++++++++++ tweepy/streaming.py | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/tweepy/api.py b/tweepy/api.py index 74188093d..daacbfe9e 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -675,6 +675,33 @@ def test(self): allowed_param = ['lat', 'long', 'name', 'contained_within'] ) + """ site stream info """ + stream_info = bind_api( + path = '{stream_id}/info.json', + payload_type = 'json', + require_auth = True, + allowed_param = ['stream_id'] + ) + + """ site stream add user """ + add_users = bind_api( + path = '{stream_id}/add_user.json', + payload_type = None, + require_auth = True, + method = 'POST', + allowed_param = ['stream_id','user_id'] + ) + + """ site stream remove user """ + remove_users = bind_api( + path = '{stream_id}/remove_user.json', + payload_type = None, + require_auth = True, + method = 'POST', + allowed_param = ['stream_id','user_id'] + ) + + """ Internal use only """ @staticmethod def _pack_image(filename, max_size): diff --git a/tweepy/streaming.py b/tweepy/streaming.py index f6d37f450..f83b4d7ec 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -246,3 +246,21 @@ def disconnect(self): return self.running = False + def follow(self, follow, async=False): + if self.running: + raise TweepError('Stream object already connected!') + + self.scheme = "https" + self.parameters = {} + self.headers['Content-type'] = "application/x-www-form-urlencoded" + self.host = 'sitestream.twitter.com' + self.url = '/%s/site.json?delimited=length' % STREAM_VERSION + + if follow: + self.parameters['follow'] = ','.join(map(str, follow)) + + self.body = urlencode_noplus(self.parameters) + self.parameters['delimited'] = 'length' + self._start(async) + + From 655ba7a49a6f652ba6d559ae5ab3e1f3ae77350e Mon Sep 17 00:00:00 2001 From: Jorge Varona Date: Wed, 22 Oct 2014 17:35:00 +0000 Subject: [PATCH 3/3] Set default 'method' to 'POST'. Added 'GET' override for sample.py call. --- tweepy/streaming.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index f83b4d7ec..98e865a0d 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -84,6 +84,7 @@ def __init__(self, auth, listener, **options): self.retry_time = options.get("retry_time", 10.0) self.snooze_time = options.get("snooze_time", 5.0) self.buffer_size = options.get("buffer_size", 1500) + self.method = 'POST' if options.get("secure", True): self.scheme = "https" else: @@ -111,10 +112,10 @@ def _run(self): conn = httplib.HTTPConnection(self.host) else: conn = httplib.HTTPSConnection(self.host) - self.auth.apply_auth(url, 'POST', self.headers, self.parameters) + self.auth.apply_auth(url, self.method, self.headers, self.parameters) conn.connect() conn.sock.settimeout(self.timeout) - conn.request('POST', self.url, self.body, headers=self.headers) + conn.request(self.method, self.url, self.body, headers=self.headers) resp = conn.getresponse() if resp.status != 200: if self.listener.on_error(resp.status) is False: @@ -210,6 +211,7 @@ def retweet(self, async=False): def sample(self, count=None, async=False): self.parameters = {'delimited': 'length'} + self.method = 'GET' if self.running: raise TweepError('Stream object already connected!') self.url = '/%s/statuses/sample.json?delimited=length' % STREAM_VERSION