-
Notifications
You must be signed in to change notification settings - Fork 0
/
bechdel_json_parser.py
29 lines (23 loc) · 784 Bytes
/
bechdel_json_parser.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
import json
import requests
import csv
# URL
url = 'http://bechdeltest.com/api/v1/getAllMovies'
# Get response for getting all the movie lists
response = requests.get(url)
json_data = json.loads(response.text)
# Length of the entire Bechdel test approved movies
print(len(json_data))
filename = "Bechdel_Approved.csv"
def write_csv(data, filename):
print("Writing..")
with open(filename, 'wt') as csv_file:
writer = csv.DictWriter(csv_file, data[0].keys())
print(data[0].keys(), data[1].keys(), data[0].values())
writer.writeheader()
for row in data:
print(row)
writer.writerow(row)
# for index in range(len(json_data)):
# writer.writerow((data[index].values()))
write_csv(json_data, filename)