diff --git a/opds/catalog.py b/opds/catalog.py index 8789199..6818c67 100644 --- a/opds/catalog.py +++ b/opds/catalog.py @@ -4,7 +4,7 @@ from urllib.parse import quote from jinja2 import Environment, FileSystemLoader, select_autoescape from .entry import Entry from .link import Link -import sqlite3 +import sqlite3,json class Catalog(object): @@ -47,14 +47,31 @@ def fromsearch(root_url, url, content_base_path, content_relative_path): return c def fromdir(root_url, url, content_base_path, content_relative_path): - - searchArr=["Girl","Bat","Part One"] + + path = os.path.join(content_base_path, content_relative_path) + #print(path) c = Catalog( title=os.path.basename(os.path.dirname(path)), root_url=root_url, url=url ) #print(c.url) + + ##########WORKING AREA########### + searchArr=[] + if c.url.endswith("/catalog"): + with open('test.json') as fi: + data=json.load(fi) + print("--> LOADED FILE") # try and get this as low as possible. + #searchArr=["Girl","Bat","Part One"] + + for e in data: + for key, value in e.items(): + searchArr.append(key) + print(searchArr) + ###################### + + if not "search" in c.url: onlydirs = [ f for f in os.listdir(path) if not os.path.isfile(os.path.join(path, f)) @@ -96,11 +113,23 @@ def fromdir(root_url, url, content_base_path, content_relative_path): #fixed issue with multiple . in filename #print(c.render()) else: - print(searchArr) + with open('test.json') as fi: + data=json.load(fi) + print("--> LOADED 2 FILE") # try and get this as low as possible. + for e in data: + for key, value in e.items(): + print(key) + searchArr.append(key) for i in searchArr: + print(i) if quote(f""+i) in c.url: - print(i) conn = sqlite3.connect('app.db') + print(data) + for e in data: + for key, value in e.items(): + print(key) + query="SELECT * FROM COMICS where " + sql="SELECT * from COMICS where SERIES like '%" + i+ "%' or Title like '%" + i+ "%';" print(sql) diff --git a/opds/test.json b/opds/test.json new file mode 100644 index 0000000..9cd1d93 --- /dev/null +++ b/opds/test.json @@ -0,0 +1,67 @@ +[ + { + "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", + "volume": [ + "2020", + "2019" + ], + "publisher": "", + "series": "", + "issue": "" + } + ] + }, + { + "Marvel": [ + { + "title": "", + "volume": "", + "publisher": "marvel", + "series": "", + "issue": "" + } + ] + }, + { + "Girl": [ + { + "title": ["girl","man","World"], + "volume": "", + "publisher": "", + "series": "girl", + "issue": "" + } + ] + }, + { + "Aquaman": [ + { + "title": "", + "volume": "", + "publisher": "", + "series": "aquaman", + "issue": ["2","3","5","10","22"] + } + ] + } +, + { + "Girl series": [ + { + "title": "", + "volume": "", + "publisher": "", + "series": "girl", + "issue": "2" + } + ] + } +] diff --git a/queryTest.py b/queryTest.py index 21f74aa..a4b0466 100644 --- a/queryTest.py +++ b/queryTest.py @@ -7,12 +7,14 @@ with open('test.json') as f: for element in data: for key, value in element.items(): title=key -# print("Search Title: " + title) query="SELECT * FROM COMICS where " +# print("Search Title: " + title) for i in value: first=True for j,k in i.items(): - if k != '': + if j == 'SQL': + query = query + k + if k != '' and j != "SQL": # print(j,k) if not first: query = query + "and "