forked from ronreiter/interactive-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
32 lines (23 loc) · 734 Bytes
/
process.py
File metadata and controls
32 lines (23 loc) · 734 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
import csv
import glob
import json
import re
data = {}
for f in glob.glob("*.csv"):
d = csv.DictReader(open(f))
for l in d:
t = f[:-4]
l = {x[0].lower().replace(" ", "_"): x[1] for x in list(l.items())}
l["retail_price"] = float(l["retail_price"])
link = re.findall(r'<a href=\"(.*?)\">', l["link_code"])[0]
image_url, pixel_url = re.findall(r'src=\"(.*?)\"', l["link_code"])
l["link"] = link
l["image_url"] = image_url
l["pixel_url"] = pixel_url
if t not in data:
data[t] = []
data[t].append(l)
encoded = json.dumps(data, sort_keys=True, indent=4)
print(encoded)
with open("../courses.json", "w") as e:
e.write(encoded)