-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
31 lines (26 loc) · 885 Bytes
/
utils.py
File metadata and controls
31 lines (26 loc) · 885 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 json
import logging
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s - %(levelname)s - %(message)s"
)
def csv_to_json(csv_file, json_file):
data = []
with open(csv_file, mode="r", encoding="utf-8") as file:
csv_reader = csv.DictReader(file)
for row in csv_reader:
try:
data.append({
"title": row["title"],
"content": row["content"],
"dir": row["dir"],
"url": row["url"],
})
except Exception as e:
logging.error("Error: %s", e)
with open(json_file, mode="w", encoding="utf-8") as file:
json.dump(data, file, indent=4)
logging.info(f"> Converted {csv_file} to {json_file}")
if __name__ == "__main__":
csv_to_json("data/data.csv", "data/data.json")