Commit 6c768121 authored by Adrien Laporte's avatar Adrien Laporte
Browse files

Begin convert

parent e946e57f
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
from textwrap import dedent
import os
import json
def makeParser() -> argparse.ArgumentParser():
"""Permet de créer le argparse initial"""
parser = argparse.ArgumentParser()
parser.add_argument(
"input",
type=argparse.FileType("r"),
help=dedent(
"""Fichier JSON à convertir
"""
),
)
parser.add_argument(
"-o",
"--output",
type=argparse.FileType("w"),
required=False,
help="""Fichier dans lequel exporter les données converties""",
)
return parser
parser = makeParser()
args = parser.parse_args()
# Ouverture des fichiers IO
json_input_file = args.input.name
json_output_file = (
args.output
if args.output is not None
else os.path.splitext(json_input_file)[0] + ".json"
)
chaton_keys = {
"name": "chaton",
"url": "chaton_website",
}
service_keys = {
# "": "type", # Ajouté après coup
"software": "software", # list → str
"public": "open",
"weight": "weight", # Todo
"consent": "consent", # Todo
"degradability": "degradability",
"url": "endpoint",
"magie_noire": "edit_link", # Kececé ?
}
software_names = {
# Générés automatiquement
"cryptpad": "Cryptpad",
"darkwire.io": "Darkwire.io",
"draw.io": "Draw.io",
"easyrtc": "EasyRTC",
"ethercalc": "Ethercalc",
"etherpad": "Etherpad",
"filetolink": "Filetolink",
"firefoxsend": "FirefoxSend",
"framadate": "Framadate",
"libreto": "Libreto",
"lstu": "LSTU",
"lufi": "Lufi",
"lutim": "Lutim",
"mycryptochat": "MyCryptoChat",
"plik": "Plik",
"polr": "Polr",
"privatebin": "Privatebin",
"rs_short": "rs-short",
"scrumblr": "Scrumblr",
"strut": "Strut",
# ajoutés main :
"mattermost": "Mattermost"
}
software_descriptions = {
# Parsés depuis les données du framagit le 24/05/2020
"Lufi": "Partage temporaire de fichiers (alternative à WeTransfer, DropSend)",
"Draw.io": "Création de schémas et diagrammes (alternative à Visio)",
"Privatebin": "Transfert de messages chiffrés (alternative à PasteBin)",
"Etherpad": "Rédaction collaborative (alternative à Google Docs)",
"Framadate": "Aide à la prise de rendez-vous (alternative à Doodle)",
"Plik": "Partage temporaire de fichiers (alternative à WeTransfer, DropSend)",
"EasyRTC": "Visioconférence (alternative à Skype, Hangouts, etc.)",
"Cryptpad": "Rédaction collaborative (alternative à Google Docs)",
"Filetolink": "Partage temporaire de fichiers (alternative à WeTransfer, DropSend)",
"Lutim": "Stockage/partage d'images (alternative à Img.ur)",
"FirefoxSend": "Partage temporaire de fichiers (alternative à WeTransfer, DropSend)",
"Polr": "Raccourcisseur d'URL (alternative à Bit.ly, tinyurl, etc.)",
"LSTU": "Raccourcisseur d'URL (alternative à Bit.ly, tinyurl, etc.)",
"Jitsi Meet": "Visioconférence (alternative à Skype, Hangouts, etc.)",
"MyCryptoChat": "Chat IRC ou Jabber (alternative à MSN)",
"Libreto": "Rédaction collaborative (alternative à Google Docs)",
"Darkwire.io": "Chat IRC ou Jabber (alternative à MSN)",
"Strut": "Présentation collaborative (alternative à Google Drive)",
"Scrumblr": "Tableau blanc collaboratif (alternative à Stoodle)",
"Ethercalc": "Tableur collaboratif (alternative à Google Sheets)",
"rs-short": "Raccourcisseur d'URL (alternative à Bit.ly, tinyurl, etc.)",
# Ajoutés à la main :
}
degradability = {"Jamais", "1 semaine", "6 mois", "12 mois"} # ToDo fonction
conv_values = {
"http": "HTTP",
"tout.e.s": "Tout⋅e⋅s",
"cercle_prive": "Cercle privé",
}
input = {"urll": "http", "a": ["out.e.s", "cercle_prive", {"b": "http",},]}
def showNode(str):
pass
# print(str)
def debug(str):
print(str)
def convertDict(d: dict, context: str = None) -> dict:
showNode(f"D : {d}, {context}")
return {
ck: cv
for (ck, cv) in [
(convertKey(k, context), convertValue(v, k))
for (k, v) in d.items()
]
if ck is not None and cv is not None
}
def convertList(l: list, context: str = None) -> list:
showNode(f"L : {l}, {context}")
return [
cv
for cv in [convertValue(item, context) for item in l]
if cv is not None
]
def convertKey(k: str, context: str = None) -> str:
showNode(f"K : {k}, {context}")
if context == "services":
return service_keys.get(k, None)
return chaton_keys.get(k, None)
def convertStr(v: str, context: str = None) -> str:
showNode(f"S : {v}, {context}")
if context == "url":
return v
elif context == "name":
return v
elif context == "type":
print("Ouiiiii")
return software_names.get(v, None)
return conv_values.get(v, None)
def convertValue(val, context: str = None):
showNode(f"V : {val}, {context}")
if type(val) is str:
return convertStr(val, context)
elif type(val) is dict:
return convertDict(val, context)
elif type(val) is list:
return convertList(val, context)
else:
return None
with open(json_input_file, "r", encoding="utf8") as input_file:
input = json.loads(input_file.read())
print(input)
print(convertValue(input))
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