Instead of just saving iit in csv file i was simplying trying to sidplay it in terminal.But I am getting error module' object has no attribute 'search'.I am really stuck with it so if anybody can help me out it would be very kindful.
Below is the detail of the code and the error I am getting.
Thanking in advance,
Sneha Saha
latitude = 51.474144 # geographical centre of search
longitude = -0.035401 # geographical centre of search
max_range = 1 # search range in kilometres
num_results = 500 # minimum results to obtain
#-----------------------------------------------------------------------
# perform a search based on latitude and longitude
# twitter API docs: https://dev.twitter.com/docs/api/1/get/search
#-----------------------------------------------------------------------
# only process a result if it has a geolocation
#-----------------------------------------------------------------------
if result["geo"]:
user = result["user"]["screen_name"]
text = result["text"]
text = text.encode('ascii', 'replace')
latitude = result["geo"]["coordinates"][0]
longitude = result["geo"]["coordinates"][1]
# now write this row to our CSV file
Hi,
I am pretty new to this process of fetching data from twitter api.I need totla number of tweets of a particular location.So i was trying out the code from the link-https://github.com/ideoforms/python-twitter-examples/blob/master/twitter-search-geo.py#L1.
Instead of just saving iit in csv file i was simplying trying to sidplay it in terminal.But I am getting error module' object has no attribute 'search'.I am really stuck with it so if anybody can help me out it would be very kindful.
Below is the detail of the code and the error I am getting. Thanking in advance, Sneha Saha
-----------------------------------------------------------------------
twitter-search-geo
- performs a search for tweets close to New Cross, and outputs
them to a CSV file.
-----------------------------------------------------------------------
import twitter import json
latitude = 51.474144 # geographical centre of search longitude = -0.035401 # geographical centre of search max_range = 1 # search range in kilometres num_results = 500 # minimum results to obtain
INPUT YOUR AUTH KEY HERE
CONSUMER_KEY = '' CONSUMER_SECRET = '' OAUTH_TOKEN = '' OAUTH_TOKEN_SECRET = ''
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET)
twitter_api = twitter.Twitter(auth=auth)
-----------------------------------------------------------------------
open a file to write (mode "w"), and create a CSV writer object
-----------------------------------------------------------------------
-----------------------------------------------------------------------
add headings to our CSV file
-----------------------------------------------------------------------
-----------------------------------------------------------------------
the twitter API only allows us to query up to 100 tweets at a time.
to search for more, we will break our search up into 10 "pages", each
of which will include 100 matching tweets.
--------------------------------------------------------------
resultcount = 0 q = "" search_results = twitter_api.search.tweets(q="test", count=100) statuses = search_results['statuses'] last_id = None
query = twitter.search.tweets(q = "test", geocode = "%f,%f,%dkm" % (latitude, longitude, max_range),count = 100,max_id=last_id)
for result in query["statuses"]:
-----------------------------------------------------------------------
last_id = result["id"]
print json.dumps(user[0:1000],indent=1) print json.dumps(text[0:1000],indent=1) print json.dumps(latitude[0:1000],indent=1) print json.dumps(longitude[0:1000],indent=1)
Error $ python /home/student/Downloads/geotag.py Traceback (most recent call last): File "/home/student/Downloads/geotag.py", line 55, in
query = twitter.search.tweets(q = "test", geocode = "%f,%f,%dkm" % (latitude, longitude, max_range),count = 100,max_id=last_id)
AttributeError: 'module' object has no attribute 'search'