Commit 0b81120b authored by Adrien Laporte's avatar Adrien Laporte
Browse files

Converter fonctionnel

parent 58053520
# Todo
- [ ] Mettre la sortie en ligne
- [ ] Supporter tous les formats
- [ ] N'exporter que les Chatons valides pour entraide.chatons.org
- [ ] S'occuper du champ `edit_link`
......@@ -12,15 +12,22 @@ args = parser.parse_args()
# Ouverture des fichiers IO
json_input_file = args.input.name
json_output_file = (
args.output
args.output.name
if args.output is not None
else os.path.splitext(json_input_file)[0] + ".json"
else os.path.splitext(json_input_file)[0] + "_converted.json"
)
output_file = open(json_output_file, "w", encoding="utf8")
with open(json_input_file, "r", encoding="utf8") as input_file:
input = json.loads(input_file.read())
converted_chaton = convert_json.convertValue(input, "chaton")
chatons = convert_json.convertChaton(converted_chaton)
for c in chatons:
print(f"Chaton : {c}\n")
converted_chaton = convert_json.convertValue(input, "chaton")
liste_chatons = convert_json.convertChatons(converted_chaton)
json.dump(
[chaton for chaton in liste_chatons],
output_file,
indent=2,
ensure_ascii=False,
)
output_file.close()
......@@ -97,6 +97,7 @@ def convertStr(v: str, context: str = None) -> str:
soft = conversion["values"]["software"].get(v, None)
if soft is None:
print(f"Software '{v}' non-existant")
# soft = v # On met la valeur maison, au cas où
return soft
return None
......@@ -124,7 +125,18 @@ def convertValue(val, context: str = None):
return None
def convertChaton(c: dict) -> list:
def convertChatonL(l: list) -> list:
return [
chaton
for converted_cs in [ # Une liste par Chaton en théorie
convertChatons(chaton)
for chaton in l
]
for chaton in converted_cs # Une seule liste à la fin
]
def convertChatonD(c: dict) -> list:
services = c['services']
chaton = c.copy()
del chaton['services']
......@@ -134,11 +146,25 @@ def convertChaton(c: dict) -> list:
]
def convertChatons(d) -> list:
if type(d) is dict:
return convertChatonD(d)
elif type(d) is list:
return convertChatonL(d)
else:
return []
def makeChatonService(c: dict, service: dict) -> dict:
nc = c.copy()
software = service.get('software')
description = conversion['descriptions']['software'].get(
service.get('software'), "Aucune description pour ce service"
software
)
if description is None:
if software is not None:
print(f"Aucune description pour {software}")
description = "Aucune description pour ce service"
nc['type'] = description
for (k, v) in service.items():
nc[k] = v
......
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