I am using tweepy.Cursor to collect tweets and it works ok, I want to improve my code for limiting the collection of tweets to given pair of coordinates through bounding_box. I have very limited knowledge of python. I need help in improving this code. Code is as follows:
import sys
import os
import jsonpickle
import tweepy
import datetime
import time
consumer_key = 'xxxxxxxxxxxxxxxxxxxxxxxxx'
consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
auth = tweepy.AppAuthHandler(consumer_key, consumer_secret)
api = tweepy.API(auth, wait_on_rate_limit=True,wait_on_rate_limit_notify=True)
maxTweets = 1000000
tweetCount = 0
stamp = time.strftime('%b%d%y%H%M')
filename = 'AFG'+stamp+'.json'
print(filename)
searchQuery = ('afghanistan OR elections')
with open(filename, 'w') as f:
for tweet in tweepy.Cursor(api.search, q=searchQuery, tweet_mode='extended').items(maxTweets):
f.write(jsonpickle.encode(tweet._json, unpicklable=False) + '\n')
tweetCount += 1
print("Downloaded {0} tweets.". format(tweetCount))
I don't know where to put bounding_box in above code.
Bounding_box for Afghanistan is: 'AF': ('Afghanistan', (60.5284298033, 29.318572496, 75.1580277851, 38.4862816432))