May-25-2022, 09:14 PM
ok got the time added and working, so now the only question is how to remove the " " around each row in the file
here is the currently working code:
here is the currently working code:
import json from datetime import datetime import pandas as pd f = open('message_1.json') data = json.load(f) lv = [] for message in data["messages"]: timestamp = datetime.fromtimestamp(message["timestamp_ms"] / 1000) date_val = timestamp.strftime('%Y-%m-%d') time_val = timestamp.strftime("%I:%M %p") if 'content' not in message: st = date_val + "," + time_val + "," + message["sender_name"] + "," + "" lv.append(st) else: st = date_val +"," + time_val + "," + message["sender_name"] + "," + message["content"] lv.append(st) df = pd.DataFrame(lv) df.to_csv('igMess.csv', header=None, index=None, mode='a') f.close()