Skip to content

Instantly share code, notes, and snippets.

@acapshaw
Created June 26, 2018 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acapshaw/771529c447fd4e85ded01a9843ee6872 to your computer and use it in GitHub Desktop.
Save acapshaw/771529c447fd4e85ded01a9843ee6872 to your computer and use it in GitHub Desktop.
Trying to Pull Tweets Specified to Certain Long/Lat...
Hi all, I'm trying to extract earthquake tweets from Twitter with specific long/lat coordinates thand en store into csv file..
However, the result returns tweets NOT specific to locaiton parameters, does anyone know why? Here is my code:
csvFile = open('seattle.csv', 'a')
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,q="#earthquake",count=100,
location= "47.6126,-122.6222, 50mi",
lang="en",
since="2017-04-03").items():
if tweet.geo != None:
## tweetlist.append(tweet.geo)
print (tweet.created_at, tweet.text)
tweettime = str(tweet.created_at)
text = str(tweet.text.encode('utf-8'))
x = str(tweet.geo['coordinates'][1])
y = str(tweet.geo['coordinates'][0])
print text
imgurl = ""
if "http" in text:
splitlist = text.split("http")
if len(splitlist) == 2:
if "http" in text:
urlhashtagsplit = splitlist[1].split(" ")
imgurl = "http" + urlhashtagsplit[0]
else:
imgurl = "http" + splitlist[1]
csvWriter.writerow([x,y,imgurl,text,tweettime])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment