+ table signed_by

main
jgenero 3 years ago
parent 86e5543789
commit 9d6b19ff8d

@ -10,7 +10,7 @@ from tqdm import tqdm
from app.app import APPPATH, db
from app.data_actes import diplomatic_type, institution, state, houses
from app.modeles import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by
from app.modeles import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by, Signed_by
db_cli = AppGroup("db")
@ -188,6 +188,28 @@ def _create_produced_by(xml_file: str, folder: str):
for data in tqdm(princes_actes, desc="Populating Produced_by..."):
Produced_by.create(**data)
def _create_signed_by(xml_file: str, folder: str):
sign_actes = []
for acte in os.listdir(folder):
acte_q = [t.id_acte for t in Acte.select().where(
Acte.numb_acte == acte.replace(".xml", ""))]
# print(acte, "==", acte_q[0])
soup = make_soup(os.path.join(folder, acte))
signatures = soup.sourceDesc.find_all("listPerson", {"type": "signatory"})
for signature in signatures:
signatories = signature.find_all("person")
for signatory in signatories:
signator = signatory.text.replace("\n", "")
if "None" != signator:
# signator = signatory.text.replace("\n", "")
sign_q = [t.id_indiv for t in Individual.select().where(
Individual.name_indiv == signator)]
# print(signator, "==", sign_q)
sign_actes.append({"produced_by_acte": acte_q[0],
"produced_by_prince": sign_q[0]})
for data in tqdm(sign_actes, desc="Populating Signed_by..."):
Produced_by.create(**data)
@db_cli.command()
def init() -> None:
@ -200,10 +222,10 @@ def init() -> None:
print("Dropping existing DB...")
db.drop_tables([Institution, State, House, Production_place,
Diplo_type, Document, Acte, Individual,
Produced_by])
Produced_by, Signed_by])
print("Re-creating schema...")
db.create_tables([Institution, State, House, Production_place,
Diplo_type, Document, Acte, Individual, Produced_by])
Diplo_type, Document, Acte, Individual, Produced_by, Signed_by])
_create_institution(institution)
_create_state(state)
_create_house(houses)
@ -219,3 +241,4 @@ def init() -> None:
print("!! name " + name + " not found in /app/static/csv/actors.csv")
_create_indiv(actors)
_create_produced_by(xml, xml_folder)
_create_signed_by(xml, xml_folder)

@ -1,3 +1,3 @@
from .data import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by
from .data import Institution, State, House, Production_place, Diplo_type, Document, Acte, Individual, Produced_by, Signed_by
__all__ = ["Institution", "State", "House", "Production_place", "Diplo_type", "Document", "Acte", "Individual", "Produced_by"]
__all__ = ["Institution", "State", "House", "Production_place", "Diplo_type", "Document", "Acte", "Individual", "Produced_by", "Signed_by"]

@ -119,3 +119,12 @@ class Produced_by(BaseModel):
class Meta:
database = db
db_table = 'Produced_by'
class Signed_by(BaseModel):
id_signed_by = peewee.AutoField()
signed_by_acte = peewee.ForeignKeyField(Acte, backref='signed_bys')
signed_by_prince = peewee.ForeignKeyField(Individual, backref='signed_bys')
class Meta:
database = db
db_table = 'Signed_by'

Loading…
Cancel
Save