0

I was using Kafka to do real time streaming in python. When the twitter data was streamed in, the timezone displayed was +0000. How can I change to a different timezone in json format to csv. Here are my coding for streaming.

class StdOutListener(StreamListener):
    def on_data(self, data):
        try:
            print(data)
            jsonData = json.loads(data)
            createdAt = jsonData['created_at']
            text = jsonData['text']
            saveThis = createdAt + " :: " + text
            saveFile = open('try3.csv','a',encoding='utf-8')
            saveFile.write(saveThis)
            saveFile.write('\n')
            saveFile.close()
            producer.send(topic_name, str.encode(data))
            return True
        except BaseException as e:
           print("Error on_data: %s" % str(e))
           return True
    def on_error(self, status):
        print (status)
Lyn
  • 23
  • 3

0 Answers0