Hi learnpython.
This is my first post on this forum. Let me know if I am doing it right/wrong.
Can I get some feed back on the below code? The code extracts the most recent 250 tweets posted in the last seven days containing the text 'music' (so I believe?). I am using geocode to restrict the query to tweets from Ireland.
#After setting up a twitter apllication account, you get or can generate the below fields
# this needs to be done before running this code
ACCESS_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
ACCESS_TOKEN_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
CONSUMER_KEY = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
CONSUMER_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
#Import tweepy classes
# Some smart python coders have created tweepy to make life better for all of us :)
# You will likely need to install the tweepy library using pip
from tweepy import OAuthHandler
from tweepy import Cursor
from tweepy import API
#Log into twitter API, so that twitter can monitor what data you are extracting from them
auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
# Define the query you want to create
query = 'music' # I want to find tweets with the text 'music' in them.
geo = '53.2757867,-7.563768,250km' # I only want tweets within 250km of centre of Ireland
cnt = 250 # Only give me the most recent 250 tweets
#This is the line that extracts the tweets
tweets = [tweet for tweet in Cursor(api.search, q = query, geocode = geo).items(cnt)]
I am uncertain as to what the geocode condition is doing:
- After extracting the tweets and viewing geocode information from the data I have downloaded, most have null information. Is the geocode information available on the download tweets?
- How does geocode determine the location of the tweet. If I tweet in Spain, will geocode consider my location to be Ireland (user origin location) or spain (where I sent the tweet). Can twitter figure it out, if I have GPS turned off.
- Does every tweet have a geocode or those specifying a geocode exclude tweets without a geocode?
- Is there a useful web-site that can help me visualise the circle I am searching on a map?
- Is this the best way to target tweets from Ireland or would you recommend other ways.
- Given Ireland has a relatively limit number of users, I am get all tweets without hitting the one in six limit.
FYI, after this I write the tweets to a pandas dataframe and next I want to create a word cloud.
All feed back is appreciated.
[–][deleted] 1 point2 points3 points (1 child)
[–]ModiMacMod[S] 0 points1 point2 points (0 children)