Python tweepy find all tweets in the Netherlands

Zuenie picture Zuenie · Dec 5, 2014 · Viewed 7.5k times · Source

UPDATE BOTTOM OF THE QUESTION:

I am attempting to create a script that generates all geocoded tweets in the Netherlands. I am a long way from getting there. While I was playing around with Tweepy I ran into a weird situation. I found a script online which could search for tweets containing a keyword. I tried to add a parameter checking for a geocode. I succeeded and the underneath script works. However, when I delete the geocode part of the tweepy.Cursos() call it does not work anymore. So this script works:

import tweepy
import csv

consumer_key = "???"
consumer_secret = "???"
access_token = "???"
access_token_secret = "???"

auth = tweepy.auth.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

# Open/Create a file to append data
csvFile = open('tweets.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)

for tweet in tweepy.Cursor(api.search,q="*",count=100,geocode="5.29126,52.132633,150km").items(100):
    print [tweet.created_at, tweet.text.encode('utf-8'), tweet.user.id, tweet.geo]
    csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8'), tweet.user.id])

UPDATE! Thank you for helping me so far. Now I have another question regarding my goal to create a script to gather all georeferenced tweets in the Netherlands.

The last part of my code should return all geocoded tweets in the Netherlands and write it into a CSV file. Unfortunately it only seems to take Tweets in the English language. Since there is no Dutch language setting, and Dutch people also Tweet in English, I do not want to set the language of the search. Why is it only searching Tweets in the English language? I do not know where I am setting this characteristic of the search.

Oh i turned around lat lon. Stupid mistake. Question is answered!

Answer

Luigi picture Luigi · Dec 6, 2014

You can only set your query string to '*' when also using the geocode parameter. A search for q='*' without a specified geocode is invalid.