X Tutup
Skip to content

Commit 34c51c2

Browse files
committed
Merge pull request bear#136 from stefano-maggiolo/master
Added access to the filter stream API.
2 parents 5dc40bd + 62f5590 commit 34c51c2

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

twitter.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4826,6 +4826,47 @@ def GetStreamSample(self, delimited=None, stall_warnings=None):
48264826
data = self._ParseAndCheckTwitter(line)
48274827
yield data
48284828

4829+
def GetStreamFilter(self, follow=None, track=None, locations=None,
4830+
delimited=None, stall_warning=None):
4831+
'''Returns a filtered view of public statuses.
4832+
4833+
args:
4834+
follow: a list of user ids to track [optional]
4835+
track: a list of expressions to track [optional]
4836+
locations: a list of pairs strings 'lat,lon', specifying
4837+
bounding boxes for the tweets' origin [optional]
4838+
delimited: specifies a message length [optional]
4839+
stall_warnings: set to True to deliver stall warnings [optional]
4840+
4841+
returns:
4842+
a twitter stream
4843+
4844+
'''
4845+
if not self.__auth:
4846+
raise TwitterError("twitter.Api instance must be authenticated")
4847+
4848+
if all((follow is None, track is None, locations is None)):
4849+
raise ValueError('No filter parameters specified.')
4850+
4851+
data = {}
4852+
if follow is not None:
4853+
data['follow'] = ','.join(follow)
4854+
if track is not None:
4855+
data['track'] = ','.join(track)
4856+
if locations is not None:
4857+
data['locations'] = ','.join(locations)
4858+
if delimited is not None:
4859+
data['delimited'] = str(delimited)
4860+
if delimited is not None:
4861+
data['stall_warning'] = str(stall_warning)
4862+
4863+
url = '%s/statuses/filter.json' % self.stream_url
4864+
json = self._RequestStream(url, 'POST', data=data)
4865+
for line in json.iter_lines():
4866+
if line:
4867+
data = self._ParseAndCheckTwitter(line)
4868+
yield data
4869+
48294870
def VerifyCredentials(self):
48304871
'''Returns a twitter.User instance if the authenticating user is valid.
48314872

0 commit comments

Comments
 (0)
X Tutup