From 2d6624161c6bb1b8ae946fc4b67408eea0475381 Mon Sep 17 00:00:00 2001 From: jgenero Date: Tue, 11 Oct 2022 18:46:54 +0200 Subject: [PATCH] + create tables state diplo-type place --- app/db_maker.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/app/db_maker.py b/app/db_maker.py index 4ea114e..1e59bbf 100644 --- a/app/db_maker.py +++ b/app/db_maker.py @@ -10,18 +10,47 @@ Update : """ +from bs4 import BeautifulSoup from peewee import * from tqdm import tqdm from modeles.princes_db_tables import db, Institution, State, Place, Diplo_type, Document, Acte from data.institution_data import institution +from data.state_data import state +from data.diplo_type_data import diplomatic_type + + +def make_soup(file): + """open a xml file and return a BeautifulSoup object""" + with open(file, 'r', encoding="utf-8") as opening: + xml = BeautifulSoup(opening, 'xml') + return xml def _create_institution(data_lst: list)-> None: for data in tqdm(data_lst, desc="Populating Institution..."): Institution.create(**data) +def _create_state(data_lst: list)-> None: + for data in tqdm(data_lst, desc="Populating State..."): + State.create(**data) + +def _create_diplo_type(data_lst: list)-> None: + for data in tqdm(data_lst, desc="Populating Diplo_type..."): + Diplo_type.create(**data) + +def _create_place(xml_file: 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) + production_places = [{"placename": xtraction} for xtraction in set(places_xtract)] + for data in tqdm(production_places, desc="Populating Place..."): + Place.create(**data) + def init(): db.connect() @@ -30,5 +59,10 @@ def init(): print("Re-creating schema...") db.create_tables([Institution, State, Place, Diplo_type, Document, Acte]) _create_institution(institution) + _create_state(state) + _create_diplo_type(diplomatic_type) + _create_place(xml) + +xml = "../bourbon-latex/charles-actes-latex.xml" init()