convert reference to BGW style, use requests library
This commit is contained in:
parent
d1e0e1a161
commit
3aedfe2741
25
app.py
25
app.py
@ -3,6 +3,8 @@ import json
|
||||
from io import BytesIO
|
||||
import zipfile
|
||||
from bs4 import BeautifulSoup
|
||||
import requests
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
||||
@ -11,7 +13,7 @@ def index():
|
||||
reference = ''
|
||||
version = ''
|
||||
verse = ''
|
||||
error = ''
|
||||
error = 'No error.'
|
||||
|
||||
if request.method == 'POST':
|
||||
reference = request.form.get('scripture_reference')
|
||||
@ -19,27 +21,24 @@ def index():
|
||||
|
||||
# Map version to ESV Bible ID
|
||||
bible_id = {
|
||||
'NRSV': 'nrs',
|
||||
'NRSV': 'nrsv',
|
||||
'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}'
|
||||
|
||||
url = f'https://api.esv.org/v2/verse?verse={reference}&bible={bible_id}'
|
||||
webfriendlyref=reference.replace(' ','%20').replace(':','%3A')
|
||||
url = f'https://www.biblegateway.com/passage/?search={webfriendlyref}&version={bible_id}'
|
||||
print(url)
|
||||
try:
|
||||
response = request.get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
response = requests.get(url)
|
||||
#response.raise_for_status()
|
||||
verse = response.text
|
||||
|
||||
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)}"
|
||||
error = f"Error fetching from Bible Gateway: {str(e)}"
|
||||
else:
|
||||
error = "Please provide both a reference and a version."
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user