|
|
|
|
@ -60,11 +60,12 @@ def _create_diplo_type(data_lst: list)-> None:
|
|
|
|
|
for data in tqdm(data_lst, desc="Populating Diplo_type..."):
|
|
|
|
|
Diplo_type.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_produc_place(xml_file: str, folder: str)-> None:
|
|
|
|
|
def _create_produc_place(folder: str)-> None:
|
|
|
|
|
"""create production place table"""
|
|
|
|
|
places_xtract = []
|
|
|
|
|
production_places = []
|
|
|
|
|
for acte in os.listdir(folder):
|
|
|
|
|
if acte.endswith(".xml"):
|
|
|
|
|
soup = make_soup(os.path.join(folder, acte))
|
|
|
|
|
for place in soup.find('placeName', {'type': 'production_place'}):
|
|
|
|
|
places_xtract.append(place)
|
|
|
|
|
@ -72,12 +73,13 @@ def _create_produc_place(xml_file: str, folder: str)-> None:
|
|
|
|
|
for data in tqdm(production_places, desc="Populating Place..."):
|
|
|
|
|
Production_place.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_doc(xml_file: str, folder: str)-> None:
|
|
|
|
|
def _create_doc(folder: str)-> None:
|
|
|
|
|
"""create doc table"""
|
|
|
|
|
details_doc = []
|
|
|
|
|
infos_doc = []
|
|
|
|
|
# 1/ get repository (doc archives) + doc collection in a list
|
|
|
|
|
for acte in os.listdir(folder):
|
|
|
|
|
if acte.endswith(".xml"):
|
|
|
|
|
soup = make_soup(os.path.join(folder, acte))
|
|
|
|
|
inst_doc = soup.repository.text
|
|
|
|
|
nb_doc_1 = soup.msIdentifier.find_all("idno", {"n": "1"})[0].text
|
|
|
|
|
@ -97,10 +99,11 @@ def _create_doc(xml_file: str, folder: str)-> None:
|
|
|
|
|
for data in tqdm(infos_doc, desc="Populating Document..."):
|
|
|
|
|
Document.create(**data)
|
|
|
|
|
|
|
|
|
|
def _create_acte(xml_file: str, folder: str)-> None:
|
|
|
|
|
def _create_acte(folder: str)-> None:
|
|
|
|
|
actes = []
|
|
|
|
|
counter = 0
|
|
|
|
|
for acte in sorted(os.listdir(folder)):
|
|
|
|
|
if acte.endswith(".xml"):
|
|
|
|
|
counter += 1
|
|
|
|
|
soup = make_soup(os.path.join(folder, acte))
|
|
|
|
|
numb = soup.TEI["xml:id"]
|
|
|
|
|
@ -142,6 +145,7 @@ def _create_acte(xml_file: str, folder: str)-> None:
|
|
|
|
|
def __find_indiv(folder: str, role: str)-> None:
|
|
|
|
|
indiv_lst = []
|
|
|
|
|
for acte in os.listdir(folder):
|
|
|
|
|
if acte.endswith(".xml"):
|
|
|
|
|
soup = make_soup(os.path.join(folder, acte))
|
|
|
|
|
xml_indivs = soup.sourceDesc.find_all("listPerson", {"type": role})
|
|
|
|
|
for xml_indiv in xml_indivs:
|
|
|
|
|
@ -157,14 +161,6 @@ def __csv_indiv_infos(indiv_type):
|
|
|
|
|
lst_of_indiv = [row for row in actors_csv if row[1] == indiv_type]
|
|
|
|
|
return lst_of_indiv
|
|
|
|
|
|
|
|
|
|
def __compareList(l1,l2):
|
|
|
|
|
l1.sort()
|
|
|
|
|
l2.sort()
|
|
|
|
|
if(l1==l2):
|
|
|
|
|
return "Equal"
|
|
|
|
|
else:
|
|
|
|
|
return "Non equal"
|
|
|
|
|
|
|
|
|
|
def _create_indiv(list_csv):
|
|
|
|
|
individuals = [{"name_indiv": actor[0], "role_indiv": actor[1],
|
|
|
|
|
"house_indiv": [t.id_house for t in House.select().where(
|
|
|
|
|
@ -187,9 +183,10 @@ def __grape_indiv(list_person, role: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _create_involved_in(xml_file: str, folder: str):
|
|
|
|
|
def _create_involved_in(folder: str):
|
|
|
|
|
princes_actes = []
|
|
|
|
|
for acte in os.listdir(folder):
|
|
|
|
|
if acte.endswith(".xml"):
|
|
|
|
|
acte_q = [t.id_acte for t in Acte.select().where(
|
|
|
|
|
Acte.filename == acte.replace(".xml", ""))]
|
|
|
|
|
# print(acte, "==", acte_q[0])
|
|
|
|
|
@ -203,13 +200,11 @@ def _create_involved_in(xml_file: str, folder: str):
|
|
|
|
|
interv_q = [t.id_intev for t in Intervention_type.select().where(
|
|
|
|
|
Intervention_type.interv_label == "producer")]
|
|
|
|
|
# print(person_text, "==", prince_q[0])
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
prince_q[0]
|
|
|
|
|
except IndexError:
|
|
|
|
|
print("!! name " + person_text + " (prince) not found in /app/static/csv/actors.csv")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
princes_actes.append({"involved_in_acte": acte_q[0],
|
|
|
|
|
"involved_in_prince": prince_q[0],
|
|
|
|
|
"invol_in_interv": interv_q[0]})
|
|
|
|
|
@ -222,13 +217,11 @@ def _create_involved_in(xml_file: str, folder: str):
|
|
|
|
|
interv_q = [t.id_intev for t in Intervention_type.select().where(
|
|
|
|
|
Intervention_type.interv_label == "signatory")]
|
|
|
|
|
# print(person_text, "==", prince_q[0])
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
prince_q[0]
|
|
|
|
|
except IndexError:
|
|
|
|
|
print("!! name " + person_text + " (signatory) not found in /app/static/csv/actors.csv")
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
princes_actes.append({"involved_in_acte": acte_q[0],
|
|
|
|
|
"involved_in_prince": prince_q[0],
|
|
|
|
|
"invol_in_interv": interv_q[0]})
|
|
|
|
|
@ -239,10 +232,8 @@ def _create_involved_in(xml_file: str, folder: str):
|
|
|
|
|
@db_cli.command()
|
|
|
|
|
def init() -> None:
|
|
|
|
|
"""Initialization of the database"""
|
|
|
|
|
xml = os.path.join(APPPATH, "static", "xml",
|
|
|
|
|
"Bourbon", "Brb_5_Charles_Ier"), ".xml"
|
|
|
|
|
xml_folder = os.path.join(APPPATH, "static", "xml",
|
|
|
|
|
"Bourbon", "Brb_5_Charles_Ier")
|
|
|
|
|
"Bourbon")
|
|
|
|
|
|
|
|
|
|
print("Dropping existing DB...")
|
|
|
|
|
db.drop_tables([Institution, State, House, Intervention_type,
|
|
|
|
|
@ -256,14 +247,10 @@ def init() -> None:
|
|
|
|
|
_create_house(houses)
|
|
|
|
|
_create_interv_type(interventions)
|
|
|
|
|
_create_diplo_type(diplomatic_type)
|
|
|
|
|
_create_produc_place(xml, xml_folder)
|
|
|
|
|
_create_doc(xml, xml_folder)
|
|
|
|
|
_create_acte(xml, xml_folder)
|
|
|
|
|
_create_produc_place(xml_folder)
|
|
|
|
|
_create_doc(xml_folder)
|
|
|
|
|
_create_acte(xml_folder)
|
|
|
|
|
# check which names need to be add to the actors.csv
|
|
|
|
|
actors = [*__csv_indiv_infos("secret"), *__csv_indiv_infos("prince")]
|
|
|
|
|
# names_in_csv = [actor[0] for actor in actors]
|
|
|
|
|
# names_in_xml = __find_indiv(xml_folder, "signatory")
|
|
|
|
|
# for name in [x for x in names_in_xml if x not in names_in_csv]:
|
|
|
|
|
# print("!! name " + name + " not found in /app/static/csv/actors.csv")
|
|
|
|
|
_create_indiv(actors)
|
|
|
|
|
_create_involved_in(xml, xml_folder)
|
|
|
|
|
_create_involved_in(xml_folder)
|
|
|
|
|
|