diff --git a/app/db_maker.py b/app/db_maker.py index 6d44d0c..00243fe 100644 --- a/app/db_maker.py +++ b/app/db_maker.py @@ -11,6 +11,7 @@ Update : import os from bs4 import BeautifulSoup +from collections import OrderedDict from peewee import * from tqdm import tqdm @@ -51,7 +52,42 @@ 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: + details_doc = {} + infos_doc = [] + for acte in os.listdir(folder): + soup = make_soup(os.path.join(folder, acte)) + # doc_id = soup.TEI["xml:id"] + inst_doc = soup.repository + nb_doc_1 = soup.msIdentifier.find_all("idno", {"n": "1"}) + diplo_state = soup.body.div["type"] + # details_doc.append([inst_doc, nb_doc_1, diplo_state]) + details_doc[nb_doc_1]= [inst_doc, diplo_state] + print(details_doc) + """ + for item in details_doc: + inst_query = [t.id_institution for t in Institution.select().where( + Institution.full_label == item[0].text)] + state_query = [t.id_state for t in State.select().where( + State.state_label == item[2])] + if len(item[1]) > 0: + # if there is a collection + infos_doc.append({ + "inst_doc": inst_query[0], + "collection_doc": item[1][0].text, + "state_doc": state_query[0], + }) + else: + # if collection is missing + infos_doc.append({ + "inst_doc": inst_query[0], + "collection_doc": "", + "state_doc": state_query[0], + }) + for data in tqdm(infos_doc, desc="Populating Document..."): + print(data) + Document.create(**data) +""" def init(): db.connect() print("Dropping existing DB...") @@ -62,7 +98,11 @@ def init(): _create_state(state) _create_diplo_type(diplomatic_type) _create_produc_place(xml, "./static/xml/Bourbon/Brb_5_Charles_Ier") + print("ok") + _create_doc(xml, "./static/xml/Bourbon/Brb_5_Charles_Ier") xml = "../bourbon-latex/charles-actes-latex.xml" -init() +# init() + +_create_doc(xml, "./static/xml/Bourbon/Brb_5_Charles_Ier")