|
|
|
|
@ -10,7 +10,7 @@ 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
|
|
|
|
|
from app.modeles import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by, Signed_by
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db_cli = AppGroup("db")
|
|
|
|
|
@ -188,6 +188,28 @@ def _create_produced_by(xml_file: str, folder: str):
|
|
|
|
|
for data in tqdm(princes_actes, desc="Populating Produced_by..."):
|
|
|
|
|
Produced_by.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_signed_by(xml_file: str, folder: str):
|
|
|
|
|
sign_actes = []
|
|
|
|
|
for acte in os.listdir(folder):
|
|
|
|
|
acte_q = [t.id_acte for t in Acte.select().where(
|
|
|
|
|
Acte.numb_acte == acte.replace(".xml", ""))]
|
|
|
|
|
# print(acte, "==", acte_q[0])
|
|
|
|
|
soup = make_soup(os.path.join(folder, acte))
|
|
|
|
|
signatures = soup.sourceDesc.find_all("listPerson", {"type": "signatory"})
|
|
|
|
|
for signature in signatures:
|
|
|
|
|
signatories = signature.find_all("person")
|
|
|
|
|
for signatory in signatories:
|
|
|
|
|
signator = signatory.text.replace("\n", "")
|
|
|
|
|
if "None" != signator:
|
|
|
|
|
# signator = signatory.text.replace("\n", "")
|
|
|
|
|
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]})
|
|
|
|
|
for data in tqdm(sign_actes, desc="Populating Signed_by..."):
|
|
|
|
|
Produced_by.create(**data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@db_cli.command()
|
|
|
|
|
def init() -> None:
|
|
|
|
|
@ -200,10 +222,10 @@ def init() -> None:
|
|
|
|
|
print("Dropping existing DB...")
|
|
|
|
|
db.drop_tables([Institution, State, House, Production_place,
|
|
|
|
|
Diplo_type, Document, Acte, Individual,
|
|
|
|
|
Produced_by])
|
|
|
|
|
Produced_by, Signed_by])
|
|
|
|
|
print("Re-creating schema...")
|
|
|
|
|
db.create_tables([Institution, State, House, Production_place,
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Produced_by])
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Produced_by, Signed_by])
|
|
|
|
|
_create_institution(institution)
|
|
|
|
|
_create_state(state)
|
|
|
|
|
_create_house(houses)
|
|
|
|
|
@ -219,3 +241,4 @@ 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)
|
|
|
|
|
|