2020-05-10 04:21:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Created on Sat May 9 09:53:25 2020
|
|
|
|
|
|
|
|
@author: francois
|
|
|
|
"""
|
|
|
|
|
2020-05-16 18:25:11 +00:00
|
|
|
import questionary as qq
|
|
|
|
import choix_entite as ce
|
2020-05-10 04:21:41 +00:00
|
|
|
import questions_entite as qe
|
2020-05-16 18:25:11 +00:00
|
|
|
import questions_relations as qr
|
2020-05-15 04:49:45 +00:00
|
|
|
import dataset
|
2020-05-16 18:25:11 +00:00
|
|
|
import pprint
|
2020-05-10 04:21:41 +00:00
|
|
|
|
|
|
|
|
2020-05-16 18:25:11 +00:00
|
|
|
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))
|
2020-05-15 04:49:45 +00:00
|
|
|
|
|
|
|
|
2020-05-16 18:25:11 +00:00
|
|
|
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
|