|
|
|
|
@ -9,8 +9,8 @@ from lxml import etree
|
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
|
|
|
|
|
from app.app import APPPATH, db
|
|
|
|
|
from app.data_actes import diplomatic_type, institution, state, houses
|
|
|
|
|
from app.modeles import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by, Signed_by
|
|
|
|
|
from app.data_actes import diplomatic_type, institution, state, houses, interventions
|
|
|
|
|
from app.modeles import Institution, State, House, Intervention_type, Production_place, Diplo_type, Document, Acte, Individual, Produced_by
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db_cli = AppGroup("db")
|
|
|
|
|
@ -50,6 +50,11 @@ def _create_house(data_lst: list)-> None:
|
|
|
|
|
for data in tqdm(data_lst, desc="Populating House..."):
|
|
|
|
|
House.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_interv_type(data_lst: list)-> None:
|
|
|
|
|
"""create state table"""
|
|
|
|
|
for data in tqdm(data_lst, desc="Populating Intervention_type..."):
|
|
|
|
|
Intervention_type.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_diplo_type(data_lst: list)-> None:
|
|
|
|
|
"""create diplo type table"""
|
|
|
|
|
for data in tqdm(data_lst, desc="Populating Diplo_type..."):
|
|
|
|
|
@ -171,6 +176,7 @@ def _create_produced_by(xml_file: str, folder: str):
|
|
|
|
|
for acte in os.listdir(folder):
|
|
|
|
|
acte_q = [t.id_acte for t in Acte.select().where(
|
|
|
|
|
Acte.numb_acte == acte.replace(".xml", ""))]
|
|
|
|
|
# print("----")
|
|
|
|
|
# print(acte, "==", acte_q[0])
|
|
|
|
|
soup = make_soup(os.path.join(folder, acte))
|
|
|
|
|
princes = soup.sourceDesc.find_all("listPerson", {"type": "prince"})
|
|
|
|
|
@ -205,10 +211,10 @@ def _create_signed_by(xml_file: str, folder: str):
|
|
|
|
|
sign_q = [t.id_indiv for t in Individual.select().where(
|
|
|
|
|
Individual.name_indiv == signator)]
|
|
|
|
|
# print(signator, "==", sign_q)
|
|
|
|
|
sign_actes.append({"produced_by_acte": acte_q[0],
|
|
|
|
|
"produced_by_prince": sign_q[0]})
|
|
|
|
|
sign_actes.append({"signed_by_acte": acte_q[0],
|
|
|
|
|
"signed_by_prince": sign_q[0]})
|
|
|
|
|
for data in tqdm(sign_actes, desc="Populating Signed_by..."):
|
|
|
|
|
Produced_by.create(**data)
|
|
|
|
|
Signed_by.create(**data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@db_cli.command()
|
|
|
|
|
@ -220,15 +226,16 @@ def init() -> None:
|
|
|
|
|
"Bourbon", "Brb_5_Charles_Ier")
|
|
|
|
|
|
|
|
|
|
print("Dropping existing DB...")
|
|
|
|
|
db.drop_tables([Institution, State, House, Production_place,
|
|
|
|
|
Diplo_type, Document, Acte, Individual,
|
|
|
|
|
Produced_by, Signed_by])
|
|
|
|
|
db.drop_tables([Institution, State, House, Intervention_type,
|
|
|
|
|
Production_place, Diplo_type, Document, Acte, Individual,
|
|
|
|
|
Produced_by])
|
|
|
|
|
print("Re-creating schema...")
|
|
|
|
|
db.create_tables([Institution, State, House, Production_place,
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Produced_by, Signed_by])
|
|
|
|
|
db.create_tables([Institution, State, House, Intervention_type,
|
|
|
|
|
Production_place, Diplo_type, Document, Acte, Individual, Produced_by])
|
|
|
|
|
_create_institution(institution)
|
|
|
|
|
_create_state(state)
|
|
|
|
|
_create_house(houses)
|
|
|
|
|
_create_interv_type(interventions)
|
|
|
|
|
_create_diplo_type(diplomatic_type)
|
|
|
|
|
_create_produc_place(xml, xml_folder)
|
|
|
|
|
_create_doc(xml, xml_folder)
|
|
|
|
|
@ -241,4 +248,3 @@ def init() -> None:
|
|
|
|
|
print("!! name " + name + " not found in /app/static/csv/actors.csv")
|
|
|
|
|
_create_indiv(actors)
|
|
|
|
|
_create_produced_by(xml, xml_folder)
|
|
|
|
|
_create_signed_by(xml, xml_folder)
|
|
|
|
|
|