-
Notifications
You must be signed in to change notification settings - Fork 15
/
generate_csv.py
33 lines (29 loc) · 1.18 KB
/
generate_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Script that is responsible for reading out of actors.json and creating the two
other user-friendly formats people may find helpful. If we update actors, then
run this script, the other two files will update automagically.
@Author https://github.com/DougTheDruid
@Source https://github.com/DougTheDruid/SoT-Actor-Names
@Framework https://github.com/DougTheDruid/SoT-ESP-Framework
For community support, please contact me on Discord: dougthedruid
"""
import json
from csv import DictWriter
if __name__ == '__main__':
# Read in our existing actors.json file
with open("actors.json", "r") as infile:
actors = json.load(infile)
# Create an inverted list version and a list of dictionary for the csv
csv_list = []
for key, val in actors.items():
csv_list.append({
'Friendly Name': key,
'Actor Name': val
})
# Dump the csv list to a csv file
with open("actors.csv", "w") as outfile_csv:
writer = DictWriter(outfile_csv,
fieldnames=['Friendly Name', 'Actor Name'],
delimiter=',', lineterminator='\n')
writer.writeheader()
writer.writerows(csv_list)