-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadingTradesJSON.py
28 lines (24 loc) · 1.16 KB
/
readingTradesJSON.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
import json
import csv
with open("trades/trades_2013.json", "r") as file:
json_data = json.load(file)
data = json.loads(json_data)
with open("trades_overview_2013_new.csv", "w+", newline="") as csvfile:
writer = csv.writer(csvfile, delimiter=";", quotechar='"', quoting=csv.QUOTE_MINIMAL)
writer.writerow(["Date", "Team", "Inflow", "Outflow"])
for row in data:
inp1 = "NA"
outp1 = "NA"
if row["inflow"]:
if "player" in row["inflow"][0]:
inp1 = row["inflow"][0]["player"]["playername"]
else:
inp1 = "{} round {} draft pick".format(row["inflow"][0]["draft_pick"]["round"],
row["inflow"][0]["draft_pick"]["year"])
if row["outflow"]:
if "player" in row["outflow"][0]:
outp1 = row["outflow"][0]["player"]["playername"]
else:
outp1 = "{} round {} draft pick".format(row["outflow"][0]["draft_pick"]["round"],
row["outflow"][0]["draft_pick"]["year"])
writer.writerow([row["date"], row["team"], inp1, outp1])