-
Notifications
You must be signed in to change notification settings - Fork 1
/
khan_academy.py
47 lines (34 loc) · 1.37 KB
/
khan_academy.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
34
35
36
37
38
39
40
41
42
43
44
45
# ----------------------------------------------
# khan_academy.py
# ----------------------------------------------
import requests
import json
from bs4 import BeautifulSoup
import csv
if __name__ == "__main__":
# ----------------------------------------------
# loading json file using curl --user
# ----------------------------------------------
d = open('khan.json', 'r')
data = json.load(d)
d.close()
# ----------------------------------------------
# writing header and other attributes
# ----------------------------------------------
with open('khan.csv', 'a') as f:
writer = csv.DictWriter(f, fieldnames = ['title', 'subject', 'interal_id', 'url', 'id_number', 'description'])
writer.writeheader()
for i in range(len(data['children'])):
title = data['children'][i]['title']
title = title.strip().replace(':', '')
title = title.strip().replace(',', '')
subject = data['translated_title']
internal_id = data['children'][i]['internal_id']
internal_id = internal_id.strip().replace(',', ' ')
id_number = data['children'][i]['node_slug']
url = data['children'][i]['url']
description = data['children'][i]['description']
description = description.strip().replace(',', ' ')
description = description.strip().replace('\n', ' ')
f.write(title + ',' + subject + ',' + internal_id + ',' +
url + ',' + id_number + ',' + description + '\n')