Some styling and code cleanup

This commit is contained in:
2023-05-26 16:15:20 -07:00
parent 39b844b698
commit 5f06c80882
5 changed files with 74 additions and 99 deletions
+35 -45
View File
@@ -5,7 +5,7 @@ from datetime import date, datetime # used for daily verse
import sqlite3
import string # for literals
import json # for dictionary
import hunspell # for spell checking
import hunspell # for spell checking (not really used)
import sys
import logging
@@ -48,7 +48,6 @@ cached = {
"html_response": open("html/response.html", "r").read(),
"html_navbar": open("html/navbar.html", "r").read(),
"css_navbar": open("styles/header.css", "r").read(),
"js_navbar": open("js/header.js", "r").read(),
"css_response": open("styles/human_readable.css", "r").read(),
"css_collapsible": open("styles/collapsible.css", "r").read(),
"js_collapsible": open("js/collapsible.js", "r").read(),
@@ -221,6 +220,7 @@ def parse_query():
if len(result) > 17:
return result
result = "<!DOCTYPE html>"
result += search()
result += "<style>" + cached["css_collapsible"] + "</style>"
result += "<h3>1828 Webster Definitions</h3> Click on the word to get the definition."
split_query = query.replace(",", " ").split(" ")
@@ -235,11 +235,11 @@ def parse_query():
+ word.capitalize()
+ "</button>"
)
result += "<div class='content'>" + definition + "</div>"
result += "<div class='definition'>" + definition + "</div>"
logging.debug(f"parse_query.define = '{word}'")
result += "<script>" + cached["js_collapsible"] + "</script>"
result += "<hr>"
result += search()
#result += search()
logging.debug(f"parse_query.search = '{result}'")
return result
@@ -354,7 +354,7 @@ def show(kw=None, get_start_verse_id=False):
logging.debug(f"show.results({results})")
for result in results:
verse_results.append(result)
response_list = response_multi(verse_results)
response_list = scripture_response(verse_results)
arg_view = request.args.get("view", None)
if arg_view == "plain":
response = "<br>".join(response_list)
@@ -395,37 +395,7 @@ def response_rich(scripture):
chapter=passage.split(":")[0], passage=passage, text=text
)
def response_single(scripture):
logging.debug(f"response_single({scripture})")
arg_view = request.args.get("view", "json")
logging.debug(f"->requested_format = {arg_view}")
if arg_view == "plain":
return response_text(scripture)
elif arg_view == "rich":
l_r_nav = get_next_prev_chapter(
str(scripture[0])
) # get the first scripture, the id thereof
return (
cached["html_navbar"].format(
query=request.args.get("kw", ""),
current_chapter_name=l_r_nav["current_chapter_name"],
next_chapter_name=l_r_nav["next_chapter_name"],
next_chapter_link=l_r_nav["next_chapter_link"],
prev_chapter_name=l_r_nav["prev_chapter_name"],
prev_chapter_link=l_r_nav["prev_chapter_link"],
)
+ cached["js_navbar"]
+ cached["css_navbar"]
+ cached["css_response"]
+ response_rich(scripture)
)
else:
response = response_dict(scripture)
return jsonify(response)
def response_multi(scriptures):
def scripture_response(scriptures):
response = []
arg_view = request.args.get("view", "json")
logging.debug(f"search ->requested_format = {arg_view}")
@@ -436,7 +406,7 @@ def response_multi(scriptures):
l_r_nav = get_next_prev_chapter(
str(scriptures[0][0])
) # get the first scripture, the id thereof
response.append(cached["css_response"])
#response.append(cached["css_response"])
response.append(
cached["html_navbar"].format(
query=request.args.get("kw", ""),
@@ -449,9 +419,11 @@ def response_multi(scriptures):
)
response.append(cached["css_navbar"])
response.append(cached["js_navbar"])
response.append("<div class='responses'")
response.append(f"{len(scriptures)} Results")
for scripture in scriptures:
response.append(response_rich(scripture))
response.append("</div>")
else:
for scripture in scriptures:
response.append(response_dict(scripture))
@@ -482,9 +454,19 @@ def salvation():
@app.get("/random")
def random_verse():
rand_id = random.SystemRandom().choice(cached["verse_ids"])
scripture = lookup_one_verse(rand_id)
#scripture = lookup_one_verse(rand_id)
scripture = lookup_by_verse_id(rand_id)
logging.info(f"Random Served: {scripture[0]}")
return response_single(scripture)
response_list = scripture_response(scripture)
arg_view = request.args.get("view", None)
if arg_view == "plain":
response = "<br>".join(response_list)
elif arg_view == "rich":
response = "<br>".join(response_list)
else:
response = jsonify(response_list)
logging.debug(f"Search Response: {response}")
return response
# backwards-compatibility
@@ -496,9 +478,17 @@ def verse_of_the_day():
today = int(str(date.today()).replace("-", ""))
# this is deterministic because of today's date being used as the seed
random.seed(today)
scripture = lookup_one_verse(random.choice(cached["verse_ids"]))
return response_single(scripture)
scripture = lookup_by_verse_id(random.choice(cached["verse_ids"]))
response_list = scripture_response(scripture)
arg_view = request.args.get("view", None)
if arg_view == "plain":
response = "<br>".join(response_list)
elif arg_view == "rich":
response = "<br>".join(response_list)
else:
response = jsonify(response_list)
logging.debug(f"Search Response: {response}")
return response
@app.get("/search")
def search():
@@ -517,7 +507,7 @@ def search():
return "{} not found, try one of the following: {}".format(
cleaned_keywords, ", ".join(suggestions)
)
response_list = response_multi(results)
response_list = scripture_response(results)
arg_view = request.args.get("view", None)
if arg_view == "plain":
response = "<br>".join(response_list)
@@ -608,7 +598,7 @@ def sequential_read(start=0, num=1, uid=None, getuid=False):
start_verse = cached["verse_ids"][nextverse]
end_verse = cached["verse_ids"][nextverse + num]
result_list = lookup_by_verse_id(start_verse, end_verse)
response_list = response_multi(result_list)
response_list = scripture_response(result_list)
logging.info(f"Served {num+1} verses to UID {uid}")
seq_cur.execute(
+11 -9
View File
@@ -1,20 +1,22 @@
<div class="topbar" align="center">
<a href="/">Home</a> | <a href="/find">Quick Search</a> |
<a href="/random?view=rich">Random Verse</a> |
<a href="/votd?view=rich">Verse of the Day</a>
</div>
<div class="header" id="NavHeader">
<header align="center">
<header>
<div class="header" id="NavHeader" align="center">
<a href="/">Home</a> |
<a href="/random?view=rich">Random Verse</a> |
<a href="/votd?view=rich">Verse of the Day</a>
<form action="/find">
<input type="text" name="kw" value="{query}" id="searchBar">
<input type="hidden" name="view" value="rich"">
<input type="submit" value="Search">
<input type="hidden" name="view" value="rich">
</form>
<
&leftarrow;
<a href="{prev_chapter_link}">{prev_chapter_name}</a> |
{current_chapter_name} |
<a href="{next_chapter_link}">{next_chapter_name}</a>
>
</header>
&rightarrow;
</div>
</header>
-19
View File
@@ -1,19 +0,0 @@
<script>
// When the user scrolls the page, execute myFunction
window.onscroll = function() {headerscroll()};
// Get the header
var header = document.getElementById("NavHeader");
// Get the offset position of the navbar
var sticky = header.offsetTop;
// Add the sticky class to the header when you reach its scroll position. Remove "sticky" when you leave the scroll position
function headerscroll() {
if (window.pageYOffset > sticky) {
header.classList.add("sticky");
} else {
header.classList.remove("sticky");
}
}
</script>
+21 -19
View File
@@ -1,30 +1,40 @@
<style>
/* Style the header */
.topbar{
padding: 10px;
.responses{
font-family: sans-serif;
font-size: 14.5pt;
width: 768px;
padding: 1px;
margin-top: 100px;
}
a {
text-align: center;
color: #547720
}
.header {
font-family: sans-serif;
padding: 10px 16px;
background: #dbd5d5;
color: #1a1919;
position: fixed;
top: 5px;
width: 768px;
}
input[type=text] {
width: 100%;
width: 75%;
padding: 12px 20px;
margin: 8px 0;
box-sizing: border-box;
text-align: center;
font-size: 14pt;
text-align: left;
font-size: 14.5pt;
}
input[type=button], input[type=submit], input[type=reset] {
font-family: sans-serif;
background-color: #afcdc2;
border: none;
color: rgb(0, 0, 0);
@@ -35,19 +45,11 @@
}
/* Page content */
.content {
padding: 16px;
}
/* The sticky class is added to the header with JS when it reaches its scroll position */
.sticky {
position: fixed;
top: 0;
.definition {
padding: 8px;
font-family: sans-serif;
font-size: 14.5pt;
width: 768px;
}
/* Add some top padding to the page content to prevent sudden quick movement (as the header gets a new position at the top of the page (position:fixed and top:0) */
.sticky + .content {
padding-top: 102px;
padding: 1px;
}
</style>
+2 -2
View File
@@ -1,7 +1,7 @@
<style>
html{
.testhtml{
font-family: sans-serif;
font-size: 14pt;
font-size: 14.5pt;
width: 768px;
}
a {