-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_resources.py
36 lines (28 loc) · 1.21 KB
/
get_resources.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
import json
import requests
from src.core.infrastructure import PostgresThreadRepository
from src.core.usecases import create_message
repository = PostgresThreadRepository()
resources = ["datasets", "discussions", "catalog.json"]
for resource in resources:
url = (
f"https://www.data.gouv.fr/api/1/organizations/ministere-de-leconomie-des-finances-et-de-la-souverainete"
f"-industrielle-et-numerique/{resource}"
)
response = requests.get(url)
data = json.dumps(response.json(), indent=2, ensure_ascii=False)
# Correction du nom de fichier pour la ressource "catalog.json"
filename = f"data/{resource}.json" if resource != "catalog.json" else "data/catalog.json"
with open(filename, "w") as file:
json.dump(response.json(), file, indent=2, ensure_ascii=False)
with open("data/messages.json", "r") as file:
data = json.load(file)
for item in data:
for message in item["discussion"]:
create_message(
repository=repository,
thread_id=item["id"],
author=message["posted_by"]["slug"],
content=message["content"],
posted_on=message["posted_on"],
)