diff --git a/main.py b/main.py index c833cd7..68c3f42 100644 --- a/main.py +++ b/main.py @@ -4,4 +4,5 @@ from src.db import * if __name__ == "__main__": sprit = Spritpreise(location="Linnich", radius=30) sprit.setDbConnection(dbHost, dbPort, dbUser, dbPassword, dbType) + sprit.createDb() #sprit.getAllPricesSchedule() \ No newline at end of file diff --git a/src/server/SpritpreisAnalysis.py b/src/server/SpritpreisAnalysis.py new file mode 100644 index 0000000..d8e266b --- /dev/null +++ b/src/server/SpritpreisAnalysis.py @@ -0,0 +1,6 @@ +import psycopg2 +from src.db import * + +class SpritpreisAnalysis: + def __init__(self): + pass \ No newline at end of file diff --git a/src/webScraper/Spritpreise.py b/src/webScraper/Spritpreise.py index 11caf7b..042dac0 100644 --- a/src/webScraper/Spritpreise.py +++ b/src/webScraper/Spritpreise.py @@ -204,3 +204,45 @@ class Spritpreise: return self + def createDb(self): + connection, cursor = self.__getDbConnection() + sql = ('CREATE SEQUENCE IF NOT EXISTS spritpreise_header_id_seq;\ + \ + -- Table Definition\ + CREATE TABLE IF NOT EXISTS "public"."spritpreis_header" (\ + "id" int4 NOT NULL DEFAULT nextval(\'spritpreise_header_id_seq\'::regclass),\ + "name" text NOT NULL,\ + "street" text NOT NULL,\ + "city" text NOT NULL,\ + PRIMARY KEY ("id")\ + );\ + -- Indices\ + CREATE UNIQUE INDEX IF NOT EXISTS spritpreise_header_pkey ON public.spritpreis_header USING btree (id);\ + CREATE INDEX IF NOT EXISTS idx ON public.spritpreis_header USING btree (city) INCLUDE (city, street) WITH (deduplicate_items=\'false\');\ + \ + CREATE SEQUENCE IF NOT EXISTS spritpreis_position_id_seq;\ + \ + -- Table Definition\ + CREATE TABLE IF NOT EXISTS "public"."spritpreis_position" (\ + "id" int4 NOT NULL DEFAULT nextval(\'spritpreis_position_id_seq\'::regclass),\ + "of_spritpreis_header" int4 NOT NULL,\ + "time" timestamptz NOT NULL,\ + "diesel_price" float4,\ + "e10_price" float4,\ + "e5_price" float4,\ + "super_plus_price" float4,\ + CONSTRAINT "foreign_idx" FOREIGN KEY ("of_spritpreis_header") REFERENCES "public"."spritpreis_header"("id") ON DELETE CASCADE,\ + PRIMARY KEY ("id")\ + );\ + -- Indices\ + CREATE INDEX IF NOT EXISTS "fki_F" ON public.spritpreis_position USING btree (of_spritpreis_header);\ + CREATE INDEX IF NOT EXISTS idx_time ON public.spritpreis_position USING btree ("time") WITH (deduplicate_items=\'true\');\ + CREATE INDEX IF NOT EXISTS idx_diesel ON public.spritpreis_position USING btree (diesel_price) INCLUDE (diesel_price) WITH (deduplicate_items=\'true\');\ + CREATE INDEX IF NOT EXISTS idx_e10 ON public.spritpreis_position USING btree (e10_price) WITH (deduplicate_items=\'true\');\ + CREATE INDEX IF NOT EXISTS idx_e5 ON public.spritpreis_position USING btree (e5_price) WITH (deduplicate_items=\'true\');\ + CREATE INDEX IF NOT EXISTS idx_super_plus ON public.spritpreis_position USING btree (super_plus_price) WITH (deduplicate_items=\'true\');') + + cursor.execute(sql) + + cursor.close() + connection.close() \ No newline at end of file