index.html and widgets
This commit is contained in:
parent
f2c27a1d41
commit
d1e0e1a161
50
app.py
50
app.py
@ -1,12 +1,52 @@
|
|||||||
from flask import Flask
|
from flask import Flask, request, render_template, send_file
|
||||||
|
import json
|
||||||
|
from io import BytesIO
|
||||||
|
import zipfile
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
def hello_world(): # put application's code here
|
def index():
|
||||||
return 'Hello World!'
|
reference = ''
|
||||||
|
version = ''
|
||||||
|
verse = ''
|
||||||
|
error = ''
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
reference = request.form.get('scripture_reference')
|
||||||
|
version = request.form.get('version')
|
||||||
|
|
||||||
|
# Map version to ESV Bible ID
|
||||||
|
bible_id = {
|
||||||
|
'NRSV': 'nrs',
|
||||||
|
'NIV': 'niv',
|
||||||
|
'NLT': 'nlt'
|
||||||
|
}.get(version)
|
||||||
|
|
||||||
|
if bible_id and reference:
|
||||||
|
# ESV API endpoint
|
||||||
|
api_key = 'YOUR_ESV_API_KEY' # Replace with your actual API key
|
||||||
|
url = f'https://api.esv.org/v2/verse?verse={reference}&bible={bible_id}&key={api_key}'
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = request.get(url)
|
||||||
|
response.raise_for_status()
|
||||||
|
data = response.json()
|
||||||
|
|
||||||
|
if data['verses']:
|
||||||
|
verse = data['verses'][0]['text']
|
||||||
|
else:
|
||||||
|
error = "Verse not found."
|
||||||
|
except request.RequestException as e:
|
||||||
|
error = f"Error fetching verse: {str(e)}"
|
||||||
|
else:
|
||||||
|
error = "Please provide both a reference and a version."
|
||||||
|
|
||||||
|
# Print to stdout
|
||||||
|
print(f"Reference: {reference}, Version: {version}, Verse: {verse}, Error: {error}")
|
||||||
|
|
||||||
|
return render_template('index.html', reference=reference, version=version, verse=verse, error=error)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run()
|
app.run()
|
||||||
|
|||||||
31
templates/index.html
Normal file
31
templates/index.html
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Scripture Reference Tool</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<h1>Scripture Reference Tool</h1>
|
||||||
|
<form method="post">
|
||||||
|
<label for="scripture_reference">Scripture Reference:</label><br>
|
||||||
|
<input type="text" id="scripture_reference" name="scripture_reference" value="{{ reference }}"><br><br>
|
||||||
|
|
||||||
|
<label for="version">Version:</label><br>
|
||||||
|
<select id="version" name="version">
|
||||||
|
<option value="NRSV" {% if version == 'NRSV' %}selected{% endif %}>NRSV</option>
|
||||||
|
<option value="NIV" {% if version == 'NIV' %}selected{% endif %}>NIV</option>
|
||||||
|
<option value="NLT" {% if version == 'NLT' %}selected{% endif %}>NLT</option>
|
||||||
|
</select><br><br>
|
||||||
|
|
||||||
|
<button type="submit">Fetch Verse</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% if verse %}
|
||||||
|
<h2>Verse:</h2>
|
||||||
|
<p>{{ verse }}</p>
|
||||||
|
{% elif error %}
|
||||||
|
<h2>Error:</h2>
|
||||||
|
<p>{{ error }}</p>
|
||||||
|
{% endif %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Loading…
x
Reference in New Issue
Block a user