endpoint comments
This commit is contained in:
@@ -271,7 +271,7 @@ def ref_parse_book(ref):
|
|||||||
return book
|
return book
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@app.get("/ref/<ref>")
|
@app.get("/ref/<ref>") # find database verse_id by english scripture reference (1John5:7)
|
||||||
def get_single_reference_verse_id(ref:str):
|
def get_single_reference_verse_id(ref:str):
|
||||||
ref = ref.split(",")[0]
|
ref = ref.split(",")[0]
|
||||||
ref = ref.split("-")[0]
|
ref = ref.split("-")[0]
|
||||||
@@ -290,8 +290,8 @@ def get_single_reference_verse_id(ref:str):
|
|||||||
return
|
return
|
||||||
return get_verse_id(ref_book_id, ref_chapter, ref_verse)
|
return get_verse_id(ref_book_id, ref_chapter, ref_verse)
|
||||||
|
|
||||||
@app.get("/sermon/<ref>")
|
@app.get("/sermon/search/<ref>") # find a sermon by english scripture reference (1John5:7)
|
||||||
def find_sermon(ref:str=None):
|
def find_sermon_by_ref(ref:str=None):
|
||||||
verse_id = get_single_reference_verse_id(ref=ref)
|
verse_id = get_single_reference_verse_id(ref=ref)
|
||||||
if not sermon_cur:
|
if not sermon_cur:
|
||||||
return jsonify({'error':"Sermon database not found"})
|
return jsonify({'error':"Sermon database not found"})
|
||||||
@@ -300,6 +300,46 @@ def find_sermon(ref:str=None):
|
|||||||
sermon.update({'kjv':find_by_verseid(sermon.get("verse_id"))[4]})
|
sermon.update({'kjv':find_by_verseid(sermon.get("verse_id"))[4]})
|
||||||
return jsonify(sermons)
|
return jsonify(sermons)
|
||||||
|
|
||||||
|
@app.get("/sermons") # lists all the sermons in our database
|
||||||
|
def list_sermons():
|
||||||
|
return jsonify(sermon_cur.execute("select distinct title,url,denomination,preacher,church_name,filename from verse_refs").fetchall())
|
||||||
|
|
||||||
|
@app.get("/sermon/<filename>/verses") # show all matched info on a sermon by its filename (hash)
|
||||||
|
def list_sermon_references(filename):
|
||||||
|
return jsonify(sermon_cur.execute("select distinct verse_id,text from verse_refs where filename=?", (filename,)).fetchall())
|
||||||
|
|
||||||
|
@app.get("/preachers") # return a list of preachers stored in database, their denomination and church name
|
||||||
|
def list_preachers():
|
||||||
|
return jsonify(sermon_cur.execute("select distinct denomination,preacher,church_name from verse_refs").fetchall())
|
||||||
|
|
||||||
|
@app.get("/churches") # return a list of churches with sermons in the database
|
||||||
|
def list_churches():
|
||||||
|
return jsonify(sermon_cur.execute("select distinct denomination,church_name from verse_refs").fetchall())
|
||||||
|
|
||||||
|
@app.get("/denominations") # return a list of denominations included in the database
|
||||||
|
def list_denominations():
|
||||||
|
return jsonify(sermon_cur.execute("select distinct denomination from verse_refs").fetchall())
|
||||||
|
|
||||||
|
@app.get("/sermons/preacher/<preacher>") # show all sermons by a paticular preacher
|
||||||
|
def find_sermons_by_preacher(preacher):
|
||||||
|
return jsonify(sermon_cur.execute("select distinct title,url,denomination,preacher,church_name from verse_refs where preacher=?", (preacher,)).fetchall())
|
||||||
|
|
||||||
|
@app.get("/sermons/church/<church_name>") # show all sermons by a paticular church
|
||||||
|
def find_sermons_by_church(church_name):
|
||||||
|
return jsonify(sermon_cur.execute("select distinct title,url,denomination,preacher,church_name from verse_refs where church_name=?", (church_name,)).fetchall())
|
||||||
|
|
||||||
|
@app.get("/sermons/denomination/<denomination>") # show all sermons by a paticular denomination
|
||||||
|
def find_sermons_by_denomination(denomination):
|
||||||
|
return jsonify(sermon_cur.execute("select distinct title,url,denomination,preacher,church_name from verse_refs where denomination=?", (denomination,)).fetchall())
|
||||||
|
|
||||||
|
@app.get("/sermon/<filename>") # show general information about a sermon by filename (hash)
|
||||||
|
def find_sermons_by_filename(filename):
|
||||||
|
return jsonify(sermon_cur.execute("select distinct title,url,denomination,preacher,church_name from verse_refs where filename=?", (filename,)).fetchall())
|
||||||
|
|
||||||
|
@app.get("/sermon/url/<url>") # show general information about a sermon by url
|
||||||
|
def find_sermons_by_url(url):
|
||||||
|
return jsonify(sermon_cur.execute("select distinct title,url,denomination,preacher,church_name from verse_refs where url=?", (url,)).fetchall())
|
||||||
|
|
||||||
def clean_verseid(verse_id):
|
def clean_verseid(verse_id):
|
||||||
verse_id = str(verse_id)
|
verse_id = str(verse_id)
|
||||||
clean_verseid = ''
|
clean_verseid = ''
|
||||||
@@ -309,13 +349,17 @@ def clean_verseid(verse_id):
|
|||||||
return clean_verseid
|
return clean_verseid
|
||||||
|
|
||||||
|
|
||||||
@app.get("/verse_id/<verse_id>")
|
|
||||||
def find_by_verseid(verse_id):
|
def find_by_verseid(verse_id):
|
||||||
|
return lookup_by_verse_id(verse_id)[0]
|
||||||
|
# wow lol I just wrote this and forgot how it works already lmao
|
||||||
|
|
||||||
|
|
||||||
|
@app.get("/verse_id/<verse_id>") # return the database entry of an internal verse_id
|
||||||
|
def web_verseid(verse_id):
|
||||||
clean_verse_id = clean_verseid(verse_id=verse_id)
|
clean_verse_id = clean_verseid(verse_id=verse_id)
|
||||||
return lookup_by_verse_id(clean_verse_id)[0]
|
return jsonify(lookup_by_verse_id(clean_verse_id)[0])
|
||||||
|
|
||||||
|
@app.get("/find") # user-facing general search parser. This will move to an independant frontend.
|
||||||
@app.get("/find")
|
|
||||||
def parse_query(query_override: str = None):
|
def parse_query(query_override: str = None):
|
||||||
query = request.args.get("kw", None)
|
query = request.args.get("kw", None)
|
||||||
# /find should always return human readable (rich) but some users may try
|
# /find should always return human readable (rich) but some users may try
|
||||||
@@ -369,7 +413,7 @@ def parse_query(query_override: str = None):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
@app.get("/define")
|
@app.get("/define") # user-facing Webster Dictionary, this will move to an independent frontend.
|
||||||
def define(word=None):
|
def define(word=None):
|
||||||
ref = request.args.get("kw", None)
|
ref = request.args.get("kw", None)
|
||||||
if word:
|
if word:
|
||||||
@@ -424,7 +468,7 @@ def return_dict_rich(ref, defs, simple):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/show")
|
@app.get("/show") # user facing to show a group of scripture. This will be deprecated and moved to backend.
|
||||||
def show(kw=None, get_start_verse_id=False, human_readable=False):
|
def show(kw=None, get_start_verse_id=False, human_readable=False):
|
||||||
ref: str = request.args.get("kw", None)
|
ref: str = request.args.get("kw", None)
|
||||||
get_chapter: bool = request.args.get("all", False)
|
get_chapter: bool = request.args.get("all", False)
|
||||||
@@ -576,8 +620,8 @@ def page_not_found(e):
|
|||||||
return jsonify(message)
|
return jsonify(message)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
@app.get("/") # index
|
||||||
@app.get("/<shortcode>")
|
@app.get("/<shortcode>") # resolves a generated shortcode
|
||||||
def idx(shortcode=""):
|
def idx(shortcode=""):
|
||||||
if not sanity:
|
if not sanity:
|
||||||
return "Sanity check failed. Check database ownership or please notify tyler@dinsmoor.us"
|
return "Sanity check failed. Check database ownership or please notify tyler@dinsmoor.us"
|
||||||
@@ -588,13 +632,13 @@ def idx(shortcode=""):
|
|||||||
return send_file("html/index.html")
|
return send_file("html/index.html")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/salvation")
|
@app.get("/salvation") # a web page about going to heaven
|
||||||
def salvation():
|
def salvation():
|
||||||
return send_file("html/heaven.html")
|
return send_file("html/heaven.html")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/t/random", defaults={"view": "plain"}) # backwards-compatibility
|
@app.get("/t/random", defaults={"view": "plain"}) # backwards-compatibility plaintext random Bible verse
|
||||||
@app.get("/random")
|
@app.get("/random") # truely random Bible verse
|
||||||
def random_verse():
|
def random_verse():
|
||||||
rand_id = random.SystemRandom().choice(cached["verse_ids"])
|
rand_id = random.SystemRandom().choice(cached["verse_ids"])
|
||||||
scripture = lookup_by_verse_id(rand_id)
|
scripture = lookup_by_verse_id(rand_id)
|
||||||
@@ -611,8 +655,8 @@ def random_verse():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.get("/t/votd", defaults={"view": "plain"}) # backwards-compatibility
|
@app.get("/t/votd", defaults={"view": "plain"}) # backwards-compatibility plaintext "Today's" Bible verse
|
||||||
@app.get("/votd")
|
@app.get("/votd") # "today's" Bible verse
|
||||||
def verse_of_the_day():
|
def verse_of_the_day():
|
||||||
# plain takes 38ms -TODO can we cache this?
|
# plain takes 38ms -TODO can we cache this?
|
||||||
logging.info("VOTD Served")
|
logging.info("VOTD Served")
|
||||||
@@ -644,7 +688,7 @@ def make_view(response_list=[]):
|
|||||||
response = jsonify(response_list)
|
response = jsonify(response_list)
|
||||||
|
|
||||||
|
|
||||||
@app.get("/search")
|
@app.get("/search") # user-facing keyword search. To be moved to backend, possibly replaced with semantic search.
|
||||||
def search():
|
def search():
|
||||||
keywords = request.args.get("kw", None)
|
keywords = request.args.get("kw", None)
|
||||||
logging.debug(f"search({keywords})")
|
logging.debug(f"search({keywords})")
|
||||||
@@ -673,7 +717,7 @@ def search():
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.get("/browse")
|
@app.get("/browse") # not implemented. TO be moved to frontend.
|
||||||
def bible_reader():
|
def bible_reader():
|
||||||
return render_template("reader.html", books=cached.get("book_names"))
|
return render_template("reader.html", books=cached.get("book_names"))
|
||||||
# We should return an index of all books with
|
# We should return an index of all books with
|
||||||
@@ -685,7 +729,7 @@ def bible_reader():
|
|||||||
# Maybe preliminary theming support
|
# Maybe preliminary theming support
|
||||||
|
|
||||||
|
|
||||||
@app.get("/plan")
|
@app.get("/plan") # not implmeneted. To be moved to frontend.
|
||||||
def reading_plan():
|
def reading_plan():
|
||||||
# needs 2 sets of data, books and time frame.
|
# needs 2 sets of data, books and time frame.
|
||||||
# should default to the entire Bible in 1 year.
|
# should default to the entire Bible in 1 year.
|
||||||
@@ -694,7 +738,7 @@ def reading_plan():
|
|||||||
return render_template("reading_plan.html")
|
return render_template("reading_plan.html")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/status")
|
@app.get("/status") # basic instance info
|
||||||
def status():
|
def status():
|
||||||
import resource
|
import resource
|
||||||
|
|
||||||
@@ -704,7 +748,7 @@ Memory: {resource.getrusage(resource.RUSAGE_SELF).ru_maxrss}
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@app.get("/seqreport")
|
@app.get("/seqreport") # shows current tracked scripture sequences
|
||||||
def sequential_report(uid=None):
|
def sequential_report(uid=None):
|
||||||
if usermode == "Single":
|
if usermode == "Single":
|
||||||
seq_conn = sqlite3.connect("data/seq.db", check_same_thread=False)
|
seq_conn = sqlite3.connect("data/seq.db", check_same_thread=False)
|
||||||
@@ -714,7 +758,7 @@ def sequential_report(uid=None):
|
|||||||
uids = seq_cur.execute("select * from reading_tracker").fetchall()
|
uids = seq_cur.execute("select * from reading_tracker").fetchall()
|
||||||
return render_template("seq_report.html", uids=uids)
|
return render_template("seq_report.html", uids=uids)
|
||||||
|
|
||||||
@app.get("/screport")
|
@app.get("/screport") # shows current remembered shortcodes
|
||||||
def shortcode_report(shortcode=None):
|
def shortcode_report(shortcode=None):
|
||||||
if usermode == "Single":
|
if usermode == "Single":
|
||||||
short_conn = sqlite3.connect("data/shortcodes.db", check_same_thread=False)
|
short_conn = sqlite3.connect("data/shortcodes.db", check_same_thread=False)
|
||||||
@@ -747,7 +791,7 @@ def sequential_purge():
|
|||||||
seq_cur.close()
|
seq_cur.close()
|
||||||
|
|
||||||
|
|
||||||
@app.get("/seq")
|
@app.get("/seq") # allows you to get groups of scripture sequentially
|
||||||
def sequential_read(start=0, num=1, uid=None, getuid=False):
|
def sequential_read(start=0, num=1, uid=None, getuid=False):
|
||||||
# /seq?uid=1
|
# /seq?uid=1
|
||||||
uid = request.args.get("uid", uid)
|
uid = request.args.get("uid", uid)
|
||||||
@@ -828,7 +872,7 @@ def sequential_read(start=0, num=1, uid=None, getuid=False):
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@app.get("/mksc/<query>")
|
@app.get("/mksc/<query>") # create and remember a new shortcode
|
||||||
def generate_shortcode(query: str = ""):
|
def generate_shortcode(query: str = ""):
|
||||||
query = search_input_cleaning(query, extra_chars=":-,")
|
query = search_input_cleaning(query, extra_chars=":-,")
|
||||||
if not query:
|
if not query:
|
||||||
@@ -881,4 +925,4 @@ if __name__ == "__main__":
|
|||||||
"Otherwise, you may end up with database corruption if multiple writes happen."
|
"Otherwise, you may end up with database corruption if multiple writes happen."
|
||||||
)
|
)
|
||||||
print("Operating in single user mode.")
|
print("Operating in single user mode.")
|
||||||
app.run(host="127.0.0.1", port=1611)
|
app.run(host="0.0.0.0", port=1612, debug=True, threaded=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user