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 :
"""
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")

Loading…
Cancel
Save