Get special tweets from Twitter tweets with Tweepy

I'm trying to get tweets from a specific location using Tweepy, but I get this error when I run the code

raise TweepError("Wrong number of locations points, " tweepy.error.TweepError: Wrong number of locations points, it has to be a multiple of 4 

In my code, I am trying to get tweets from New York with location coordinates for New York. How can I get tweets from New York? I suggest using a range of coordinates between x, y and y, z. How can I do it?

Here is my code:

 class StdOutListener(StreamListener): """ A listener handles tweets are the received from the stream. This is a basic listener that just prints received tweets to stdout. """ def on_data(self, data): try: print(data) saveFile = open('newtweets.csv', 'a') saveFile.write(data) saveFile.write('/n').encode("utf-8") saveFile.close() return True except BaseException: print ('failed ondata') time.sleep(5) def on_error(self, status): print(status.encode("utf-8")) if __name__ == '__main__': l = StdOutListener() auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) #ASK FOR KEYWORD TO COLLECT DATA user_keyword=input("What keyword do you want to mine?") stream = Stream(auth, l) stream.filter(locations=[40.7127,74.0059], track=[user_keyword]) 
+5
source share
1 answer

He needs 4 coordinates. NYC, for example:

stream.filter(locations=[-74.1687,40.5722,-73.8062,40.9467])

Here is the first result of a google site that allows you to draw bounding fields. Select CSV format in the lower left corner of the page.

It is important to note that, as mentioned in this post, you cannot filter by location keyword or by keyword.

+3
source

Source: https://habr.com/ru/post/1242530/


All Articles