-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjson2csv.py
More file actions
21 lines (17 loc) · 752 Bytes
/
json2csv.py
File metadata and controls
21 lines (17 loc) · 752 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Author: Ashvin Roharia
#
# Converts a message.json file to a clean csv file with Date, Name, and Text columns.
# A message.json file can be exported from any DM or groupchat from groupme.com.
import json
import csv
from datetime import datetime
timestamp = 0
# Open the existing json file for loading into a variable
with open("message.json", encoding='utf-8') as f:
transcript = json.load(f)
# Write the json content into an organized csv file
with open('message.csv', 'w', newline='', encoding='utf-8') as f:
for message in transcript:
timestamp = datetime.utcfromtimestamp(message['created_at']).strftime('%Y-%m-%d %H:%M:%S')
writer = csv.writer(f)
writer.writerow([timestamp, message['name'] , message['text']])