How to restrict the results of a Twitter search to

2019-05-24 07:19发布

I'm playing with the Twitter API to brush up on my basic python. I'm building an app to scan tweets from my country (Ireland) for profanity on a county by county basis, to see what's popular and to graph the results.

I'm using the python-twitter library. To preserve my budget of hits to Twitter, I'd like to only get results from Ireland. The way I have it at the moment is: 1. Search all tweets for the word "FU**" using python-twitter's GetSearch(). 2. This gives a list of statuses: Pull the screen_name from each one, this is used to get the user. GetUser() 3. The user has valid data or " " for the Location field(user specified). 4. Check for county names in this field.

I've also done a test which uses the coordinates embedded in a status, but most users have this switched off. It works well, when it works.

So, without using these, can I restrict the search to one country?

1条回答
欢心
2楼-- · 2019-05-24 08:05

The most straight forward way is to use the geocode parameter when using the search api, that should "and" together your query string and coordinates you provide.

If that doesn't provide enough results, you could also use geo/reverse_geocode. You would query for coordinates within your country, store the returned place names and data in a set. Then just do a plain query string search and see if any of those tweets places field is in your set.

查看更多
登录 后发表回答