# -*- coding: utf-8 -*- #Générateur Rationel d'Organisations Spéciales, Complexes, Ordinaires ou Nationales import json import re from collections import defaultdict from random import choice pattern = re.compile(r"(?P(?:\w{1,3}\W)*(?P\w)\S{2,}\w)") noms = [defaultdict(set), defaultdict(set)] # https://www.data.gouv.fr/fr/datasets/referentiel-de-lorganisation-administrative-de-letat/#/resources with open(r"./dila_refOrga_admin_Etat_fr_20230719.json", 'r', encoding="utf-8") as f: services = json.load(f)["service"] for service in services: matches = pattern.finditer(service["nom"]) premier_match = next(matches) noms[0][premier_match.group("initiale").upper()].add(premier_match.group("mot")) for match in matches: noms[1][match.group("initiale").upper()].add(match.group("mot")) noms[0] = {initiale: sorted(noms) for initiale, noms in sorted(noms[0].items())} noms[1] = {initiale: sorted(noms) for initiale, noms in sorted(noms[1].items())} with open(r"noms.json", 'w', encoding="utf-8") as f: json.dump(noms, f) def baptise(sigle): sigle = sigle.upper() return choice(noms[0][sigle[0].upper()]) + " " + " ".join( choice(noms[1][lettre]) for lettre in sigle[1:] )