|
|
|
|
@ -16,7 +16,7 @@ from bs4 import BeautifulSoup
|
|
|
|
|
from peewee import *
|
|
|
|
|
from tqdm import tqdm
|
|
|
|
|
|
|
|
|
|
from modeles.princes_db_tables import db, Institution, State, Production_place, Diplo_type, Document, Acte, Individual, Duke
|
|
|
|
|
from modeles.princes_db_tables import db, Institution, State, Production_place, Diplo_type, Document, Acte, Individual, Duke, Produced_by
|
|
|
|
|
|
|
|
|
|
from data.institution_data import institution
|
|
|
|
|
from data.state_data import state
|
|
|
|
|
@ -111,6 +111,7 @@ def _create_acte(xml_file: str, folder: str)-> None:
|
|
|
|
|
"numb_acte": numb,
|
|
|
|
|
"date_time": date_time,
|
|
|
|
|
"date": date,
|
|
|
|
|
"prod_place_acte": place_query[0],
|
|
|
|
|
"analysis": analyse,
|
|
|
|
|
"doc_acte": doc_query[0],
|
|
|
|
|
"ref_acte": ref_acte,
|
|
|
|
|
@ -120,14 +121,14 @@ def _create_acte(xml_file: str, folder: str)-> None:
|
|
|
|
|
for data in tqdm(actes, desc="Populating Actes..."):
|
|
|
|
|
Acte.create(**data)
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
def __find_indiv(xml_soup, role: str, indiv_lst: list)-> None:
|
|
|
|
|
princes = xml_soup.sourceDesc.find_all("listPerson", {"type": role})
|
|
|
|
|
for prince in princes:
|
|
|
|
|
dukes = prince.find_all("person")
|
|
|
|
|
for duke in dukes:
|
|
|
|
|
indiv_lst.append(duke.text.replace("\n", ""))
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
def _create_individual(xml_file: str, folder: str)-> None:
|
|
|
|
|
indiv_prince = []
|
|
|
|
|
indiv_secret = []
|
|
|
|
|
@ -163,6 +164,27 @@ def _create_duke():
|
|
|
|
|
for data in tqdm(dukes, desc="Populating Duke..."):
|
|
|
|
|
Duke.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_produced_by(xml_file: str, folder: str):
|
|
|
|
|
princes_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))
|
|
|
|
|
princes = soup.sourceDesc.find_all("listPerson", {"type": "prince"})
|
|
|
|
|
for prince in princes:
|
|
|
|
|
dukes = prince.find_all("person")
|
|
|
|
|
for duke in dukes:
|
|
|
|
|
prince = duke.text.replace("\n", "")
|
|
|
|
|
prince_q = [t.id_indiv for t in Individual.select().where(
|
|
|
|
|
Individual.name_indiv == duke.text.replace("\n", ""))]
|
|
|
|
|
duke_q = [t.id_duke for t in Duke.select().where(
|
|
|
|
|
Duke.indiv_duke == prince_q[0])]
|
|
|
|
|
# print(prince, "==", prince_q[0], "==", duke_q[0])
|
|
|
|
|
princes_actes.append({"produced_by_acte": acte_q[0],
|
|
|
|
|
"produced_by_prince": duke_q[0]})
|
|
|
|
|
for data in tqdm(princes_actes, desc="Populating Produced_by..."):
|
|
|
|
|
Produced_by.create(**data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -171,10 +193,12 @@ def init():
|
|
|
|
|
db.connect()
|
|
|
|
|
print("Dropping existing DB...")
|
|
|
|
|
db.drop_tables([Institution, State, Production_place,
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Duke])
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Duke,
|
|
|
|
|
Produced_by])
|
|
|
|
|
print("Re-creating schema...")
|
|
|
|
|
db.create_tables([Institution, State, Production_place,
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Duke])
|
|
|
|
|
Diplo_type, Document, Acte, Individual, Duke,
|
|
|
|
|
Produced_by])
|
|
|
|
|
_create_institution(institution)
|
|
|
|
|
_create_state(state)
|
|
|
|
|
_create_diplo_type(diplomatic_type)
|
|
|
|
|
@ -183,9 +207,11 @@ def init():
|
|
|
|
|
_create_acte(xml, xml_folder)
|
|
|
|
|
_create_indiv()
|
|
|
|
|
_create_duke()
|
|
|
|
|
_create_produced_by(xml, xml_folder)
|
|
|
|
|
|
|
|
|
|
xml = "../bourbon-latex/charles-actes-latex.xml"
|
|
|
|
|
xml_folder = "./static/xml/Bourbon/Brb_5_Charles_Ier"
|
|
|
|
|
|
|
|
|
|
init()
|
|
|
|
|
# _create_individual(xml, xml_folder)
|
|
|
|
|
# _create_produced_by(xml, xml_folder)
|
|
|
|
|
|