table produc_place : new script for multiple files

main
jgenero 3 years ago
parent 0a730421ac
commit 67a6f51ea1

@ -9,7 +9,7 @@ Date : 2022-10-11
Update : Update :
""" """
import os
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from peewee import * from peewee import *
from tqdm import tqdm 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..."): for data in tqdm(data_lst, desc="Populating Diplo_type..."):
Diplo_type.create(**data) Diplo_type.create(**data)
def _create_produc_place(xml_file: str)-> None: def _create_produc_place(xml_file: str, folder: str)-> None:
places_xtract = [] places_xtract = []
production_places = [] production_places = []
soup = make_soup(xml_file) for acte in os.listdir(folder):
for div in soup.find_all('div', {'xml:id': True}): soup = make_soup(os.path.join(folder, acte))
for place in div.find_all('placeName', {'type': 'production_place'}): for place in soup.find('placeName', {'type': 'production_place'}):
places_xtract.append(place.text) places_xtract.append(place)
production_places = [{"placename": xtraction} for xtraction in set(places_xtract)] production_places = [{"placename": xtraction} for xtraction in set(places_xtract)]
for data in tqdm(production_places, desc="Populating Place..."): for data in tqdm(production_places, desc="Populating Place..."):
Place.create(**data) Production_place.create(**data)
def init(): def init():
db.connect() db.connect()
print("Dropping existing DB...") 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...") 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_institution(institution)
_create_state(state) _create_state(state)
_create_diplo_type(diplomatic_type) _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" xml = "../bourbon-latex/charles-actes-latex.xml"
init() init()
# _create_produc_place(xml, "./static/xml/Bourbon/Brb_5_Charles_Ier")

Loading…
Cancel
Save