Reputation: 371
Is it possible to filter a Tweepy Search by a country code? I know it's possible to search by giving a countries coordinates and radius. However, most countries are not defined well by a circle. It seems there should be a way because you can access the tweets country code after the search is over.
Upvotes: 1
Views: 6176
Reputation: 1432
This can be method to fetch from a particular country.
api = tweepy.API(auth)
places = api.geo_search(query="USA",granularity="country")
place_id = places[0].id
tweets = api.search(q="place:%s" % place_id)
Upvotes: 2
Reputation: 452
I worked on tweepy for a while to track down tweets from all countries. Refer to this : Streaming Parameters. What you can do if u want to track tweets from a single county is as follows:
I guess this will help you in narrowing down tweets to your target country. Below is geopy code to extract country code from string value (like "New york", "brisbane" etc).
from geopy.geocoders import Yandex
import json
geolocator = Yandex(lang='en_US')
location = geolocator.geocode("Paris", timeout=10)
if location != None:
print json.dumps(location.raw, indent=4)
print location.address
print location.latitude, " -> ", location.longitude
else:
print location
Refer to Geopy Documentation. And for further assistance My Project Presentation.
Upvotes: 4