diff --git a/lib/db.py b/lib/db.py index c419491..4f94f62 100644 --- a/lib/db.py +++ b/lib/db.py @@ -46,7 +46,7 @@ def importdb(file,importdb,table): def createnwview(file): with sqlite3.connect(file) as connection: - cmd_create_nw_table = f"""CREATE VIEW "Nordwest-SCHWEIZ" AS SELECT * FROM jobs as b + cmd_create_nw_table = f"""CREATE VIEW IF NOT EXISTS "Nordwest-SCHWEIZ" AS SELECT * FROM jobs as b WHERE EXISTS (SELECT GDENAME FROM Cantons as w where w.GDEKT = 'ZH' AND @@ -62,6 +62,19 @@ def createnwview(file): cursor = connection.cursor() cursor.execute(cmd_create_nw_table) print("db connection",connection.total_changes) + createFilterTable(file) + +def createFilterTable(file): + with sqlite3.connect(file) as connection: + cmd_create_filter_table = f"""CREATE TABLE IF NOT EXISTS filters(cmd TEXT);""" + cursor = connection.cursor() + cursor.execute(cmd_create_filter_table) + print("db connection:",connection.total_changes) +def addFineFilter(file,table,filterstr): + with sqlite3.connect(file) as connection: + cmd = f"""INSERT INTO {table}(cmd) VALUES(?);""" + cursor = connection.cursor() + cursor.execute(cmd,(filterstr,)) def writedb(jobs): with sqlite3.connect("../db/sqlite3.db") as connection: diff --git a/lib/sysparse.py b/lib/sysparse.py index 76920f5..02f2b5e 100644 --- a/lib/sysparse.py +++ b/lib/sysparse.py @@ -40,8 +40,7 @@ def parse(**kwargs): args = parser.parse_args() if args.test: - session = makeSession(sys.argv[args.test]) - choose_scraper(arg.test,session) + addFineFilter("../db/sqlite3.db","filters","testfilterentry") if args.importregiondb: importdb("../db/sqlite3.db","../db/Cantons.db","Cantons") if args.initdb: