From 9d17c39ee4240ab1f40a8023689d53d39d95db8c Mon Sep 17 00:00:00 2001 From: Petr Šmerkl <46304018+SveterCZE@users.noreply.github.com> Date: Sun, 20 Jun 2021 16:30:44 +0200 Subject: add feature to display vacant OIs --- db_creation.py | 33 +++++++++++++++++++++++++---- justice_build.py | 9 ++++---- main.py | 2 +- models.py | 12 +++++++++++ templates/extract-actual.html | 37 ++++++++++++++++++++++++++++++++- templates/extract.html | 48 +++++++++++++++++++++++++++++++++++++++++-- update_db.py | 39 +++++++++++++++++++++++++++++------ 7 files changed, 162 insertions(+), 18 deletions(-) diff --git a/db_creation.py b/db_creation.py index cf9d504..0e6299a 100644 --- a/db_creation.py +++ b/db_creation.py @@ -197,7 +197,8 @@ def create_tables(conn): podily = """ CREATE TABLE "podily" ( "id" INTEGER NOT NULL UNIQUE, - "spolecnik_id" INTEGER NOT NULL, + "spolecnik_id" INTEGER, + "uvolneny_podil_id" INTEGER, "zapis_datum" DATE, "vymaz_datum" DATE, "druh_podilu_id" INTEGER, @@ -209,6 +210,7 @@ def create_tables(conn): "splaceni_text" TEXT, FOREIGN KEY("druh_podilu_id") REFERENCES "druhy_podilu"("id"), FOREIGN KEY("spolecnik_id") REFERENCES "spolecnici"("id"), + FOREIGN KEY("uvolneny_podil_id") REFERENCES "spolecnici_uvolneny_podil"("id"), PRIMARY KEY("id" AUTOINCREMENT) ); """ @@ -324,6 +326,17 @@ def create_tables(conn): FOREIGN KEY("company_id") REFERENCES "companies"("id") ); """ + spolecnici_uvolneny_podil = """ CREATE TABLE "spolecnici_uvolneny_podil" ( + "id" INTEGER NOT NULL UNIQUE, + "company_id" INTEGER NOT NULL, + "zapis_datum" DATE, + "vymaz_datum" DATE, + "text_uvolneny_podil" TEXT, + PRIMARY KEY("id" AUTOINCREMENT), + FOREIGN KEY("company_id") REFERENCES "companies"("id") + ) """ + + statutarni_organ_clen_relation = """ CREATE TABLE "statutarni_organ_clen_relation" ( "id" INTEGER NOT NULL UNIQUE, "statutarni_organ_id" INTEGER NOT NULL, @@ -444,7 +457,7 @@ def create_tables(conn): list_of_tables = [companies, adresy_v2, akcie, dr_relation, dr_organ_clen_relation, druhy_podilu, fyzicke_osoby, insolvency_events, jediny_akcionar, konkurz_events, nazvy, ostatni_skutecnosti, pocty_clenu_DR, pocty_clenu_organu, podily, pravni_formy, pravni_formy_relation, pravnicke_osoby, predmety_cinnosti, predmety_cinnosti_relation, prdmety_podnikani, predmety_podnikani_relation, - prokura_common_texts, prokuriste, sidlo_relation, spolecnici, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, + prokura_common_texts, prokuriste, sidlo_relation, spolecnici, spolecnici_uvolneny_podil, statutarni_organ_clen_relation, statutarni_organ_relation, statutarni_organy, ubo, ucel, ucel_relation, zakladni_kapital, zapis_soudy, zpusoby_jednani, zpusoby_jednani_relation] for elem in list_of_tables: try: @@ -570,6 +583,10 @@ def create_indices(conn): "spolecnik_id" ); """ + podily3 = """ CREATE INDEX "index podily3" ON "podily" ( + "uvolneny_podil_id" +); """ + pravni_formy = """ CREATE INDEX "index pravni_formy" ON "pravni_formy" ( "pravni_forma" ); """ @@ -694,6 +711,14 @@ def create_indices(conn): "adresa_id" ); """ + spolecnici_uvolneny_podil1 = """ CREATE INDEX "index uvolneny_podil1" on "spolecnici_uvolneny_podil" ( + "id" +); """ + + spolecnici_uvolneny_podil2 = """ CREATE INDEX "index uvolneny_podil2" on "spolecnici_uvolneny_podil" ( + "company_id" +); """ + statutarni_organy = """ CREATE INDEX "index statutarn_organy" ON "statutarni_organy" ( "id", "statutarni_organ_text" @@ -800,11 +825,11 @@ def create_indices(conn): list_of_indices = [companies1, companies2, companies3, companies4, companies5, adresy1, adresy2, adresy3, akcie, akcie2, akcionari1, akcionari2, akcionari3, dr_clen_relation1, dr_clen_relation2, dr_relation, dr_relation2, dr_relation_3, dr_relation_4, insolvency1, insolvency2, konkurz1, konkurz2, nazvy1, nazvy2, nazvy3, ostatni_skutecnosti, ostatni_skutecnosti2, - pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, + pocty_clenu_organ1, pocty_clenu_organ2, podily1, podily2, podily3, pravni_formy, pravni_formy_relation1, pravni_formy_relation2, predmety_cinnosti_relation1, predmety_cinnosti_relation2, predmety_cinnosti_relation3, predmety_podnikani_relation1, predmety_podnikani_relation2, predmety_podnikani_relation3, predmety_cinnosti1, predmety_cinnosti2, predmety_podnikani1, predmety_podnikani2, prokuriste1, prokuriste2, prokuriste3, prokuriste4, sidlo_relation1, sidlo_relation_2, sidlo_relation_3, soudni_zapis1, soudni_zapis2, spolecnici1, - spolecnici2, spolecnici3, spolecnici4, spolecnici5, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, + spolecnici2, spolecnici3, spolecnici4, spolecnici5, spolecnici_uvolneny_podil1, spolecnici_uvolneny_podil2, statutarni_organy, statutarni_organy_relation1, statutarni_organy_relation2, statutarni_organy_relation_3, statutarni_organy_relation_4, zakladni_kapital1, zakladni_kapital2, zpusob_jednani, zpusob_jednani_relation1, zpusob_jednani_relation2, zpusob_jednani_relation3, pravnicke_osoby1, pravnicke_osoby2, pravnicke_osoby3, pravnicke_osoby4, statutarni_organy_relation_5, fyzicke_osoby1, ubo1, ubo2, ubo3, ucel1, ucel2, ucel_relation1, ucel_relation2, ucel_relation3] i = 0 diff --git a/justice_build.py b/justice_build.py index 5850340..4b82660 100644 --- a/justice_build.py +++ b/justice_build.py @@ -6,12 +6,13 @@ import os def main(): DB_name = "justice.db" - backup_DB() + # backup_DB() create_DB(DB_name) - valid_files = get_valid_filenames() + # valid_files = get_valid_filenames() + valid_files = ["sro-full-ceske_budejovice-2021"] os.makedirs("data", exist_ok=True) - for valid_file in valid_files: - download_data(valid_file) + # for valid_file in valid_files: + # download_data(valid_file) for valid_file in valid_files: modified_file_name = os.path.join(str(os.getcwd()), "data", valid_file + ".xml") update_DB(modified_file_name, DB_name) diff --git a/main.py b/main.py index deb9d51..80b598e 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ from models import Company, Insolvency_Events, Konkurz_Events, Predmet_Podnikani from models import Zakladni_Kapital, Akcie, Nazvy, Sidlo, Sidlo_Association, Pravni_Forma_Association_v2, Pravni_Formy, Statutarni_Organ_Association, Statutarni_Organy, Pocty_Clenu_Organu from models import Zpusob_Jednani_Association, Zpusob_Jednani, Statutarni_Organ_Clen_Association, Fyzicka_Osoba, Spolecnici_Association, Podily_Association, Druhy_Podilu, Pravnicka_Osoba from models import Prokurista_Association, Dozorci_Rada_Clen_Association, Jediny_Akcionar_Association, Prokura_Common_Text_Association, Soudni_Zapisy, Ucel, Ucel_Association -from models import Adresy_v2 +from models import Adresy_v2, Uvolneny_Podil_Association from tables import Results from sqlalchemy.sql import select from sqlalchemy.sql import text diff --git a/models.py b/models.py index 6c1b84c..4b94374 100644 --- a/models.py +++ b/models.py @@ -301,6 +301,16 @@ class Spolecnici_Association(db.Model): podily = db.relationship("Podily_Association") company = db.relationship("Company") +class Uvolneny_Podil_Association(db.Model): + __tablename__ = "spolecnici_uvolneny_podil" + id = db.Column(db.Integer, primary_key=True) + company_id = db.Column(db.Integer, db.ForeignKey('companies.id')) + zapis_datum = db.Column(MyType) + vymaz_datum = db.Column(MyType) + text_uvolneny_podil = db.Column(db.String) + podily = db.relationship("Podily_Association") + company = db.relationship("Company") + class Ubo(db.Model): __tablename__ = "ubo" id = db.Column(db.Integer, primary_key=True) @@ -356,6 +366,7 @@ class Podily_Association(db.Model): __tablename__ = "podily" id = db.Column(db.Integer, primary_key=True) spolecnik_id = db.Column(db.Integer, db.ForeignKey('spolecnici.id')) + uvolneny_podil_id = db.Column(db.Integer, db.ForeignKey('spolecnici_uvolneny_podil.id')) zapis_datum = db.Column(MyType) vymaz_datum = db.Column(MyType) druh_podilu_id = db.Column(db.Integer, db.ForeignKey('druhy_podilu.id')) @@ -409,6 +420,7 @@ class Company(db.Model): statutarni_organ_text = db.relationship("Statutarni_Organ_Association") dozorci_rada_text = db.relationship("Dozorci_Rada_Association") spolecnici = db.relationship("Spolecnici_Association") + spolecnici_uvolneny_podil = db.relationship("Uvolneny_Podil_Association") prokurista = db.relationship("Prokurista_Association") prokura_common_text = db.relationship("Prokura_Common_Text_Association") jediny_akcionar = db.relationship("Jediny_Akcionar_Association") diff --git a/templates/extract-actual.html b/templates/extract-actual.html index 6bc51fe..f24cb80 100644 --- a/templates/extract-actual.html +++ b/templates/extract-actual.html @@ -49,6 +49,14 @@ {% endif %} {% endfor %} + +{% set vacant_shares_notes = [] %} +{% for i in range (row.spolecnici_uvolneny_podil|length) %} + {% if row.spolecnici_uvolneny_podil[i].vymaz_datum == 0 %} + {% set vacant_shares_notes = vacant_shares_notes.append(row.spolecnici_uvolneny_podil[i]) %} + {% endif %} +{% endfor %} + {% set sole_shareholder_notes = [] %} {% for i in range (row.jediny_akcionar|length) %} {% if row.jediny_akcionar[i].vymaz_datum == 0 %} @@ -368,7 +376,7 @@ - {% if spolecnici_notes|length > 0 %} + {% if spolecnici_notes|length > 0 or vacant_shares_notes|length > 0 %}