add filters to db

This commit is contained in:
ccppi 2024-06-18 09:58:54 +02:00
parent e5185c2f25
commit 5644c43a61
2 changed files with 15 additions and 3 deletions

View File

@ -46,7 +46,7 @@ def importdb(file,importdb,table):
def createnwview(file): def createnwview(file):
with sqlite3.connect(file) as connection: 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 WHERE EXISTS
(SELECT GDENAME FROM Cantons as w (SELECT GDENAME FROM Cantons as w
where w.GDEKT = 'ZH' AND where w.GDEKT = 'ZH' AND
@ -62,6 +62,19 @@ def createnwview(file):
cursor = connection.cursor() cursor = connection.cursor()
cursor.execute(cmd_create_nw_table) cursor.execute(cmd_create_nw_table)
print("db connection",connection.total_changes) 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): def writedb(jobs):
with sqlite3.connect("../db/sqlite3.db") as connection: with sqlite3.connect("../db/sqlite3.db") as connection:

View File

@ -40,8 +40,7 @@ def parse(**kwargs):
args = parser.parse_args() args = parser.parse_args()
if args.test: if args.test:
session = makeSession(sys.argv[args.test]) addFineFilter("../db/sqlite3.db","filters","testfilterentry")
choose_scraper(arg.test,session)
if args.importregiondb: if args.importregiondb:
importdb("../db/sqlite3.db","../db/Cantons.db","Cantons") importdb("../db/sqlite3.db","../db/Cantons.db","Cantons")
if args.initdb: if args.initdb: