TIMEX
TIMEX

Reputation: 271604

How do I use the Twitter streaming API?

stream.filter(locations=[-122.75,36.8,-121.75,37.8,-74,40,-73,41],track=["twitpic"])

This works. However, it's not "AND". It's "OR". This line gets the location OR keyword. How do I make it "AND"?

Here's the code to the library I'm using:

def filter(self, follow=None, track=None, async=False, locations=None):
        self.parameters = {}
        self.headers['Content-type'] = "application/x-www-form-urlencoded"
        if self.running:
            raise TweepError('Stream object already connected!')
        self.url = '/%i/statuses/filter.json?delimited=length' % STREAM_VERSION
        if follow:
            self.parameters['follow'] = ','.join(map(str, follow))
        if track:
            self.parameters['track'] = ','.join(map(str, track))
        if locations and len(locations) > 0:
            assert len(locations) % 4 == 0
            self.parameters['locations'] = ','.join(['%.2f' % l for l in locations])
        self.body = urllib.urlencode(self.parameters)
        self.parameters['delimited'] = 'length'
        self._start(async)

https://github.com/joshthecoder/tweepy/blob/master/tweepy/streaming.py

Upvotes: 1

Views: 2058

Answers (1)

soulseekah
soulseekah

Reputation: 9162

http://dev.twitter.com/pages/streaming_api_methods#locations

Bounding boxes are logical ORs. A locations parameter may be combined with track parameters, but note that all terms are logically ORd, so the query string track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area.

...

Multiple bounding boxes may be specified by concatenating latitude/longitude pairs, for example: locations=-122.75,36.8,-121.75,37.8,-74,40,-73,41 would track tweets from San Francisco and New York City.

For more information read the full documentation.

Upvotes: 2

Related Questions