-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_json.py
57 lines (49 loc) · 1.48 KB
/
export_json.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
46
47
48
49
50
51
52
53
54
55
56
57
from typing import List, Dict
import json
from datetime import date, time, datetime, timedelta
from data_model import Bénévole, Lieu, Type_de_quête, Quête
def to_json(result: Dict[Quête, List[Bénévole]]):
json_arr = []
for q, participants in result.items():
quête = {}
quête["name"] = q.nom
quête["quest_id"] = q.id
quête["volunteers_id"] = list(map(lambda b: b.id, participants))
quête["start"] = q.début.isoformat(sep="T")
quête["end"] = q.fin.isoformat(sep="T")
quête["locked"] = False
json_arr.append(quête)
return json.dumps(json_arr)
def write_json(result: Dict[Quête, List[Bénévole]], file="result.json"):
acc = {}
splits = []
i = 0
for q, l in result.items():
i += 1
acc[q] = l
if i >= 100:
splits.append(acc)
acc = {}
i = 0
if i >= 0:
splits.append(acc)
i = 0
for split in splits:
i += 1
name = f"{file}.{i}.json"
result = to_json(split)
with open(name, "w") as text_file:
text_file.write(result)
# [
# {
# "name":"Nom de la quête",
# "quest_id":"04dabbe6d82b45d3a3bd1d357aad3098",
# "volunteers_id":[
# "e8dc719d-49a2-4605-b9ca-c9ec1adf4589",
# "2ec5761c-473a-4a8a-ab1e-de5622ae0871"
# ],
# "start":"2024-07-03T14:20:00.000000Z",
# "end":"2024-07-03T18:20:00.000000Z",
# "locked":true
# }
# ]