Commit 58053520 authored by Adrien Laporte's avatar Adrien Laporte
Browse files

Converter : début conversion

parent 16cd7dee
......@@ -20,7 +20,7 @@ json_output_file = (
with open(json_input_file, "r", encoding="utf8") as input_file:
input = json.loads(input_file.read())
print(input)
print()
print(convert_json.convertValue(input, "chaton"))
converted_chaton = convert_json.convertValue(input, "chaton")
chatons = convert_json.convertChaton(converted_chaton)
for c in chatons:
print(f"Chaton : {c}\n")
......@@ -96,7 +96,7 @@ def convertStr(v: str, context: str = None) -> str:
elif context == "software":
soft = conversion["values"]["software"].get(v, None)
if soft is None:
print(f"Software {soft} non-existant")
print(f"Software '{v}' non-existant")
return soft
return None
......@@ -122,3 +122,25 @@ def convertValue(val, context: str = None):
return convertList(val, context)
else:
return None
def convertChaton(c: dict) -> list:
services = c['services']
chaton = c.copy()
del chaton['services']
return [
makeChatonService(chaton, service)
for service in services
]
def makeChatonService(c: dict, service: dict) -> dict:
nc = c.copy()
description = conversion['descriptions']['software'].get(
service.get('software'), "Aucune description pour ce service"
)
nc['type'] = description
for (k, v) in service.items():
nc[k] = v
return nc
{
"name": "Picasoft",
"url": "https://picasoft.net",
"services": [
{
"type": "rss",
"software": "mattermost",
"degradability" : 12
}
],
"structure": "association",
"status": "approuve"
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment