forked from r-boulland/Company-Website-Disclosure
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_to_csv.py
More file actions
33 lines (30 loc) · 778 Bytes
/
json_to_csv.py
File metadata and controls
33 lines (30 loc) · 778 Bytes
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
# -*- coding: cp1252 -*-
import json
import csv
import os
#set the directory where the JSON files are located
directory='C:/Users/Boulland/json/'
#set the directory where the CSV files will be created
outdir='C:/Users/Boulland/csv/'
s=""
for filename in os.listdir(directory):
out=os.path.join(outdir,os.path.splitext(filename)[0])
seq=(out,".csv")
out=s.join(seq)
ticker=os.path.join(directory,filename)
print(ticker)
data_file=open(ticker)
try:
data=json.load(data_file)
except:
continue
data_file.close
csv_file=open(out,'w',newline='')
print(out)
writer=csv.writer(csv_file)
for element in data:
try:
writer.writerow(element)
except:
continue
csv_file.close()