I'm using Twitter's streaming api to extract tweets using Tweepy and write them to a json file. So far, i've extracted the tweets successfully and wrote them to a json file using file write but when i try to use json package i get error as mentioned in the code below.
def on_data(self, data):
#to convert data to dict format since twitter data is in string format
json_data = json.loads(data)
try:
with open('twitter_data.json','ab') as f:
if 'limit' in json_data.keys():
return True
else:
#This method works
#f.write(json.dumps(json_data)+ "\n")
#this one does not as it concatenates dict i.e different dict are not separated by a comma
json.dump(json_data,f)
return True
except BaseException as e:
print e
logging.debug('Error %s',e)
return True