To append just the text field to a CSV file, use:
def on_data(self, data):
j_data = json.loads(data)
tweet = j_data[u"text"]
with open('tweetDB1.csv', 'a') as save_file:
save_file.write('{}::{}\n'.format(time.time(), tweet.encode('utf8'))
This loads the original JSON data into a dictionary, uses just the text
field, and encodes it to UTF-8 when writing to the file.
Your version used the JSON-encoded string, ignoring the j_data
dictionary altogether. You could just as well have removed the json.loads()
call. JSON uses \u....
escape sequences to represent Unicode codepoints. The above writes UTF-8 data instead.