From 67a6f51ea150b41dd3be321c39a3e75b2052b78e Mon Sep 17 00:00:00 2001 From: jgenero Date: Wed, 12 Oct 2022 16:34:58 +0200 Subject: [PATCH] table produc_place : new script for multiple files --- app/db_maker.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/app/db_maker.py b/app/db_maker.py index 7fd3db6..f19baa1 100644 --- a/app/db_maker.py +++ b/app/db_maker.py @@ -9,7 +9,7 @@ Date : 2022-10-11 Update : """ - +import os from bs4 import BeautifulSoup from peewee import * from tqdm import tqdm @@ -40,29 +40,30 @@ 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)-> None: +def _create_produc_place(xml_file: str, folder: str)-> None: places_xtract = [] production_places = [] - soup = make_soup(xml_file) - for div in soup.find_all('div', {'xml:id': True}): - for place in div.find_all('placeName', {'type': 'production_place'}): - places_xtract.append(place.text) + for acte in os.listdir(folder): + soup = make_soup(os.path.join(folder, acte)) + for place in soup.find('placeName', {'type': 'production_place'}): + places_xtract.append(place) production_places = [{"placename": xtraction} for xtraction in set(places_xtract)] for data in tqdm(production_places, desc="Populating Place..."): - Place.create(**data) + Production_place.create(**data) def init(): db.connect() print("Dropping existing DB...") - db.drop_tables([Institution, State, Place, Diplo_type, Document, Acte]) + db.drop_tables([Institution, State, Production_place, Diplo_type, Document, Acte]) print("Re-creating schema...") - db.create_tables([Institution, State, Place, Diplo_type, Document, Acte]) + db.create_tables([Institution, State, Production_place, Diplo_type, Document, Acte]) _create_institution(institution) _create_state(state) _create_diplo_type(diplomatic_type) - _create_produc_place(xml) + _create_produc_place(xml, "./static/xml/Bourbon/Brb_5_Charles_Ier") xml = "../bourbon-latex/charles-actes-latex.xml" init() +# _create_produc_place(xml, "./static/xml/Bourbon/Brb_5_Charles_Ier")