Files
kjv_api/tools/sanity_check.py
tyler a597e2be07 Redesign UI with modern dark theme and improved styling
- Unified color scheme using CSS variables across all pages
- Fixed spacing issues in verse display (removed <br> joins for rich view)
- Updated all HTML pages with proper HTML5 structure
- Added responsive design with mobile breakpoints
- Created shared stylesheet (styles/page.css) for form pages
- Fixed unclosed div tag in scripture_response
- Improved typography with serif fonts for scripture text
- Added verse container cards with hover effects
- Inline dark background to prevent white flash on navigation

All endpoints remain backward compatible with existing functionality.
2025-10-19 22:33:43 -07:00

60 lines
2.1 KiB
Python

# Check if all the files needed by kjv-api (to write to) are also owned by the user running it.
# if this is not the same, writing to data/seq.db (and other undesirable behavior) is inevitable
# and will save a lot of headache in the future.
#Additionally, proper CHMOD value is 664 for the database
from os import stat, getuid
def check_sanity():
check_database_permissions()
def check_database_permissions():
from os.path import exists
dependancies = ['data/seq.db', "data/shortcodes.db"]
current_uid = getuid()
for dependancy in dependancies:
# Skip check if file doesn't exist yet - SQLite will create it on first use
if not exists(dependancy):
continue
if stat(dependancy).st_uid != current_uid:
raise PermissionError(dependancy)
def check_queries(url=None):
try:
import requests
except ImportError:
raise ImportError("You must install the requests python3 module")
endpoints: list = 'show find search seq status votd random define'.split(" ")
viewarguments: list = 'rich plain json'.split(" ")
with open("tools/search_keywords.txt") as f:
keywords = f.read().splitlines()
log = []
baseurl = "http://localhost:1611"
if url:
baseurl = url
for endpoint in endpoints:
for viewargument in viewarguments:
for keyword in keywords:
testurl = f"{baseurl}/{endpoint}?view={viewargument}&kw={keyword}"
r = requests.get(testurl)
log.append([testurl, r.status_code])
with open("tools/sanity_results.txt", 'r+') as logfile:
for logged in log:
if logged[1] != 200:
logfile.write(f"{logged[1]} - {logged[0]}\n")
print(f"{logged[1]} - {logged[0]}\n")
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser("Endpoint testing for your kjv api.")
parser.add_argument('url', type=str, nargs='?', help="like http://localhost:1611")
args = parser.parse_args()
if not args.url:
print("Trying default http://localhost:1611")
url = "http://localhost:1611"
check_queries(url=args.url)