Dictionary frontend and integration
This commit is contained in:
@@ -4,6 +4,7 @@ import random
|
|||||||
from datetime import date # used for daily verse
|
from datetime import date # used for daily verse
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import string # for literals
|
import string # for literals
|
||||||
|
import json # for dictionary
|
||||||
DEBUG = 0
|
DEBUG = 0
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -27,6 +28,7 @@ def dbg2(message):
|
|||||||
dbg("Debug Level 1 Enabled")
|
dbg("Debug Level 1 Enabled")
|
||||||
dbg2("Debug Level 2 Enabled")
|
dbg2("Debug Level 2 Enabled")
|
||||||
|
|
||||||
|
dictionary_json = "1828_Webster_KJV.json"
|
||||||
kjv_cur = sqlite3.connect("kjv.db").cursor()
|
kjv_cur = sqlite3.connect("kjv.db").cursor()
|
||||||
verse_ids = [i[0] for i in kjv_cur.execute("SELECT id FROM fts_kjv;").fetchall()]
|
verse_ids = [i[0] for i in kjv_cur.execute("SELECT id FROM fts_kjv;").fetchall()]
|
||||||
book_names = [i[0] for i in kjv_cur.execute("SELECT n FROM key_english").fetchall()]
|
book_names = [i[0] for i in kjv_cur.execute("SELECT n FROM key_english").fetchall()]
|
||||||
@@ -147,14 +149,48 @@ def search_input_cleaning(query, valid_chars=string.ascii_letters + string.digit
|
|||||||
cleaned_query.append(character)
|
cleaned_query.append(character)
|
||||||
return ''.join(cleaned_query)
|
return ''.join(cleaned_query)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def ref_parse_book(ref):
|
def ref_parse_book(ref):
|
||||||
for book in reversed(book_names):
|
for book in reversed(book_names):
|
||||||
if book.startswith(ref):
|
if book.startswith(ref):
|
||||||
return book
|
return book
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@app.get("/define")
|
||||||
|
def define():
|
||||||
|
ref = request.args.get("kw", None)
|
||||||
|
if not ref:
|
||||||
|
return send_file("html/dictionary.html")
|
||||||
|
with open(dictionary_json, 'r') as data:
|
||||||
|
dictionary = json.load(data)
|
||||||
|
if not ref in dictionary.keys():
|
||||||
|
return "{} not found".format(ref)
|
||||||
|
|
||||||
|
arg_view = request.args.get("view", None)
|
||||||
|
if arg_view == "plain":
|
||||||
|
response = return_dict_plain(ref, dictionary[ref])
|
||||||
|
elif arg_view == "rich":
|
||||||
|
response = return_dict_rich(ref, dictionary[ref])
|
||||||
|
else:
|
||||||
|
response = jsonify({ref:dictionary[ref]})
|
||||||
|
|
||||||
|
return response
|
||||||
|
|
||||||
|
def return_dict_plain(ref, defs):
|
||||||
|
response = ''
|
||||||
|
for e in defs:
|
||||||
|
response += e + "<br><br>"
|
||||||
|
return ref.capitalize() + "<br><br>" + response
|
||||||
|
|
||||||
|
def return_dict_rich(ref, defs):
|
||||||
|
css = open('human_readable.css', 'r')
|
||||||
|
response_html = open('response.html', 'r')
|
||||||
|
|
||||||
|
response = ''
|
||||||
|
for e in defs:
|
||||||
|
response += e + "<br><br>"
|
||||||
|
|
||||||
|
return (response_html.read().format(passage = ref.capitalize(), text = response) + css.read())
|
||||||
|
|
||||||
@app.get("/show")
|
@app.get("/show")
|
||||||
def show():
|
def show():
|
||||||
ref = request.args.get("kw", "John 3:16")
|
ref = request.args.get("kw", "John 3:16")
|
||||||
@@ -322,10 +358,8 @@ def search():
|
|||||||
cleaned_keywords = search_input_cleaning(keywords)
|
cleaned_keywords = search_input_cleaning(keywords)
|
||||||
if not cleaned_keywords:
|
if not cleaned_keywords:
|
||||||
return send_file("html/search.html")
|
return send_file("html/search.html")
|
||||||
#return ("Invalid Query: Special Characters")
|
|
||||||
else:
|
else:
|
||||||
return send_file("html/search.html")
|
return send_file("html/search.html")
|
||||||
#return ("No Query")
|
|
||||||
|
|
||||||
results = lookup_fts(cleaned_keywords)
|
results = lookup_fts(cleaned_keywords)
|
||||||
response_list = response_multi(results)
|
response_list = response_multi(results)
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
<h2>Bible Dictionary</h2>
|
||||||
|
<form action="/define">
|
||||||
|
<label for='kw'>Word lookup</label><br>
|
||||||
|
<input type="text" name="kw"><br><br>
|
||||||
|
|
||||||
|
<label for='view'>View<label><br>
|
||||||
|
<input type="radio" name="view" value="rich">Rich<br>
|
||||||
|
<input type="radio" name="view" value="plain">Plain<br>
|
||||||
|
<input type="radio" name="view" value="json">JSON<br>
|
||||||
|
|
||||||
|
<input type="submit">
|
||||||
|
<form>
|
||||||
|
<p>This tool uses an abridged 1828 Noah Webster dictionary.</p>
|
||||||
+2
-1
@@ -18,8 +18,9 @@ html{
|
|||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://api.1611.social/random">/random</a> - A random verse from the KJV</li>
|
<li><a href="https://api.1611.social/random">/random</a> - A random verse from the KJV</li>
|
||||||
<li><a href="https://api.1611.social/votd">/votd</a> - A random verse that changes from day-to-day.</li>
|
<li><a href="https://api.1611.social/votd">/votd</a> - A random verse that changes from day-to-day.</li>
|
||||||
<li><a href="https://api.1611.social/search?kw=faith">/search</a> - Search keywords</li>
|
<li><a href="https://api.1611.social/search">/search</a> - Search keywords</li>
|
||||||
<li><a href="https://api.1611.social/show?kw=John3:16">/show</a> - Show a set of verses</li>
|
<li><a href="https://api.1611.social/show?kw=John3:16">/show</a> - Show a set of verses</li>
|
||||||
|
<li><a href="https://api.1611.social/define">/define</a> - Show a set of verses</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3>Verse searching</h3>
|
<h3>Verse searching</h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user