Starting json2query in catalog.py

This commit is contained in:
FrederikBaerentsen 2022-06-07 16:16:18 +02:00
parent 135b9b7202
commit b1b204ba2e
3 changed files with 105 additions and 7 deletions

View File

@ -4,7 +4,7 @@ from urllib.parse import quote
from jinja2 import Environment, FileSystemLoader, select_autoescape from jinja2 import Environment, FileSystemLoader, select_autoescape
from .entry import Entry from .entry import Entry
from .link import Link from .link import Link
import sqlite3 import sqlite3,json
class Catalog(object): class Catalog(object):
@ -48,13 +48,30 @@ def fromsearch(root_url, url, content_base_path, content_relative_path):
def fromdir(root_url, url, content_base_path, content_relative_path): 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) path = os.path.join(content_base_path, content_relative_path)
#print(path) #print(path)
c = Catalog( c = Catalog(
title=os.path.basename(os.path.dirname(path)), root_url=root_url, url=url title=os.path.basename(os.path.dirname(path)), root_url=root_url, url=url
) )
#print(c.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: if not "search" in c.url:
onlydirs = [ onlydirs = [
f for f in os.listdir(path) if not os.path.isfile(os.path.join(path, f)) 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 #fixed issue with multiple . in filename
#print(c.render()) #print(c.render())
else: 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: for i in searchArr:
if quote(f""+i) in c.url:
print(i) print(i)
if quote(f""+i) in c.url:
conn = sqlite3.connect('app.db') 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+ "%';" sql="SELECT * from COMICS where SERIES like '%" + i+ "%' or Title like '%" + i+ "%';"
print(sql) print(sql)

67
opds/test.json Normal file
View File

@ -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"
}
]
}
]

View File

@ -7,12 +7,14 @@ with open('test.json') as f:
for element in data: for element in data:
for key, value in element.items(): for key, value in element.items():
title=key title=key
# print("Search Title: " + title)
query="SELECT * FROM COMICS where " query="SELECT * FROM COMICS where "
# print("Search Title: " + title)
for i in value: for i in value:
first=True first=True
for j,k in i.items(): for j,k in i.items():
if k != '': if j == 'SQL':
query = query + k
if k != '' and j != "SQL":
# print(j,k) # print(j,k)
if not first: if not first:
query = query + "and " query = query + "and "