etat_libre_2020/entites.py
2020-05-16 14:25:11 -04:00

62 lines
1.6 KiB
Python
Executable file

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat May 9 09:53:25 2020
@author: francois
"""
import questionary as qq
import choix_entite as ce
import questions_entite as qe
import questions_relations as qr
import dataset
import pprint
def saisie_entite():
choix_entite = qq.prompt(ce.choix_entite('entite', 'entite'))['entite']
pp.pprint(choix_entite)
reponses = qq.prompt(qe.questions_entite[choix_entite])
pp.pprint(reponses)
try:
table = db[choix_entite]
table.insert(reponses)
except Exception as e:
print("Erreur dans l'insertion:"+str(e))
def saisie_relation():
reponses = qq.prompt(qr.questions_relations)
pp.pprint("Réponse:\n"+str(reponses))
try:
table = db[reponses['entite1']+"_"+reponses['entite2']]
nom1 = db[reponses['entite1']].columns[0]
nom2 = db[reponses['entite2']].columns[0]
reponses_insert = {nom1: reponses['id_entite1'],
nom2: reponses['id_entite2'],
'description': reponses['description']}
table.insert(reponses_insert)
except Exception as e:
print("Erreur dans l'insertion:"+str(e))
psql_string = 'postgresql://etatdulibre:etatdulibre@172.20.0.2/etatdulibre'
db = dataset.connect(psql_string)
pp = pprint.PrettyPrinter(indent=4)
quitter = 0
while quitter == 0:
m0 = qq.select(
"Entité ou relation?",
choices=[
'entite',
'relation',
'quitter'
]).ask()
if m0 == 'entite':
saisie_entite()
elif m0 == 'relation':
saisie_relation()
else:
quitter = 1