-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_samples.py
84 lines (64 loc) · 2.4 KB
/
_samples.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"""
Script pour télécharger et indexer les cas tests
"""
import json
from collections import OrderedDict
import loguru
import xmltodict
import dpe.ademe as ademe
if __name__ == "__main__":
# file = "_list_open3CL.txt"
file = "_list.txt"
DOWNLOAD = True
PERSIST = True
with open(f"./assets/samples/{file}") as f:
ids = [line.rstrip() for line in f]
index = OrderedDict()
for id in ids:
if DOWNLOAD:
file_path = f"assets/samples/{id}.xml" if PERSIST else None
xmlstring = ademe.download_xmlstring(id, file_path)
else:
file_path = f"assets/samples/{id}.xml"
xmlstring = ademe.load_xmlstring(file_path)
numero_dpe, statut, enum_version_id, xmltree = ademe.get_xmltree(xmlstring)
root = xmltree.getroot()
enum_modele_dpe_id = xmltree.xpath("administratif/date_etablissement_dpe")[
0
].text
date_visite_diagnostiqueur = xmltree.xpath(
"administratif/date_visite_diagnostiqueur"
)[0].text
date_etablissement_dpe = xmltree.xpath("administratif/date_etablissement_dpe")[
0
].text
enum_methode_application_dpe_log_id = int(
xmltree.xpath(
"logement/caracteristique_generale/enum_methode_application_dpe_log_id"
)[0].text
)
surface_habitable_logement = float(
xmltree.xpath(
"logement/caracteristique_generale/surface_habitable_logement"
)[0].text
)
nombre_niveau_logement = int(
xmltree.xpath("logement/caracteristique_generale/nombre_niveau_logement")[
0
].text
)
date_format = "%Y-%m-%d"
index[id] = {
"numero_dpe": numero_dpe,
"statut": statut,
"enum_version_id": enum_version_id,
"enum_modele_dpe_id": enum_modele_dpe_id,
"date_visite_diagnostiqueur": date_visite_diagnostiqueur,
"date_etablissement_dpe": date_etablissement_dpe,
"enum_methode_application_dpe_log_id": enum_methode_application_dpe_log_id,
"surface_habitable_logement": surface_habitable_logement,
"nombre_niveau_logement": nombre_niveau_logement,
}
print(id)
with open("./assets/samples/index.json", "w+") as f:
json.dump(index, f, indent=4)