From d0786ec2651b7edad9fe20a26fbadc181c3a9fda Mon Sep 17 00:00:00 2001 From: FrederikBaerentsen Date: Tue, 7 Jun 2022 16:28:58 +0200 Subject: [PATCH] Simple Smart list implemented --- opds/catalog.py | 47 +++++++++++++++++++++++++++++++++++++++++++---- opds/test.json | 10 ++++++++++ test.json | 16 ++++++++++++++++ 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/opds/catalog.py b/opds/catalog.py index 6818c67..a4e0ef9 100644 --- a/opds/catalog.py +++ b/opds/catalog.py @@ -128,13 +128,52 @@ def fromdir(root_url, url, content_base_path, content_relative_path): for e in data: for key, value in e.items(): print(key) - query="SELECT * FROM COMICS where " - + if key == i: + query="SELECT * FROM COMICS where " + for i in value: + first=True + for j,k in i.items(): + if j == 'SQL': + query = query + k + if k != '' and j != "SQL": + # print(j,k) + if not first: + query = query + "and " + if type(k) == list: + # print(k) + if j == "series" or j == "title": + firstS = True + query = query + "(" + for l in k: + if not firstS: + query = query + "or " + query = query + j + " like '%" + l + "%' " + if firstS: + firstS = False + query = query + ") " + else: + query = query + j + " in (" + firstL = True + for l in k: + if not firstL: + query = query + "," + query = query + "'" + l + "'" + if firstL: + firstL = False + query = query + ") " - sql="SELECT * from COMICS where SERIES like '%" + i+ "%' or Title like '%" + i+ "%';" + else: + query = query + j + " like '%" + k + "%' " + if first: + first = False + query = query + ";" + print("----> " + query) + + sql = query + #sql="SELECT * from COMICS where SERIES like '%" + i+ "%' or Title like '%" + i+ "%';" print(sql) s = conn.execute(sql) - list=[] + #list=[] for r in s: #print(r) tUrl=f""+r[7].replace("/home/drudoo/ComicsTest/Comics/","/content/") diff --git a/opds/test.json b/opds/test.json index 9cd1d93..5c095f2 100644 --- a/opds/test.json +++ b/opds/test.json @@ -20,6 +20,16 @@ ] }, { + "DC (BAT)": [ + { + "title": "", + "volume": "", + "publisher": "DC Comics", + "series": "Bat", + "issue": "" + } + ] + },{ "Marvel": [ { "title": "", diff --git a/test.json b/test.json index 0e5e0b7..5c095f2 100644 --- a/test.json +++ b/test.json @@ -1,5 +1,11 @@ [ { + "SQL TEST": [ + { + "SQL": "(series like '%Aqua%' or series like '%girl%') and issue in ('1','2','5','10') and title not like '%Annual%'" + } + ] + },{ "Man 2020,2019": [ { "title": "Man", @@ -14,6 +20,16 @@ ] }, { + "DC (BAT)": [ + { + "title": "", + "volume": "", + "publisher": "DC Comics", + "series": "Bat", + "issue": "" + } + ] + },{ "Marvel": [ { "title": "",