diff --git a/ACV.db b/ACV.db new file mode 100644 index 0000000..78dbb27 Binary files /dev/null and b/ACV.db differ diff --git a/OEB.db b/OEB.db new file mode 100644 index 0000000..f941f38 Binary files /dev/null and b/OEB.db differ diff --git a/__pycache__/apikey.cpython-310.pyc b/__pycache__/apikey.cpython-310.pyc new file mode 100644 index 0000000..846f5b4 Binary files /dev/null and b/__pycache__/apikey.cpython-310.pyc differ diff --git a/__pycache__/timeout.cpython-310.pyc b/__pycache__/timeout.cpython-310.pyc new file mode 100644 index 0000000..38072eb Binary files /dev/null and b/__pycache__/timeout.cpython-310.pyc differ diff --git a/asv.db b/asv.db new file mode 100644 index 0000000..e2841d9 Binary files /dev/null and b/asv.db differ diff --git a/main.py b/main.py new file mode 100644 index 0000000..a1ab52c --- /dev/null +++ b/main.py @@ -0,0 +1,126 @@ +import time +import re +import random +import sched +import sqlite3 +import datetime + +DBCON = sqlite3.connect("./acv.db") +CURSOR = DBCON.cursor() +BIBLE_BOOKS = [ + "Genesis", + "Exodus", + "Leviticus", + "Numbers", + "Deuteronomy", + "Joshua", + "Judges", + "Ruth", + "1 Samuel", + "2 Samuel", + "1 Kings", + "2 Kings", + "1 Chronicles", + "2 Chronicles", + "Ezra", + "Nehemiah", + "Esther", + "Job", + "Psalm", + "Proverbs", + "Ecclesiastes", + "Song of Solomon", + "Isaiah", + "Jeremiah", + "Lamentations", + "Ezekiel", + "Daniel", + "Hosea", + "Joel", + "Amos", + "Obadiah", + "Jonah", + "Micah", + "Nahum", + "Habakkuk", + "Zephaniah", + "Haggai", + "Zechariah", + "Malachi", + "Matthew", + "Mark", + "Luke", + "John", + "Acts", + "Romans", + "1 Corinthians", + "2 Corinthians", + "Galatians", + "Ephesians", + "Philippians", + "Colossians", + "1 Thessalonians", + "2 Thessalonians", + "1 Timothy", + "2 Timothy", + "Titus", + "Philemon", + "Hebrews", + "James", + "1 Peter", + "2 Peter", + "1 John", + "2 John", + "3 John", + "Jude", + "Revelation", +] + + +def get_time(): + gettime = datetime.datetime.now() + time = gettime.strftime("%H:%M") + return time + + +def choose_book(): + rand_book = random.choice(BIBLE_BOOKS) + book_index = BIBLE_BOOKS.index(rand_book) + return (book_index, rand_book) + + +def get_verse(): + curr_time = get_time() + extract = "" + verse = int(curr_time.split(":")[1]) + chap = int(curr_time.split(":")[0]) + data = [] + while not data: + if chap > 12: + hour = [chap, chap-12] + chap = random.choice(hour) + book_tuple = choose_book() + # book_tuple = (5, 'Deuteronomy') + book_index = book_tuple[0]+1 + book = book_tuple[1] + data = CURSOR.execute( + f"select text from acv_verses where book_id == {book_index} and chapter == {chap} and verse == {verse}" + ).fetchall() + if data: + break + DBCON.commit() + verse_text = data[0][0] + print(f""" + Book: {book} + Chapter: {chap} + Verse: {verse} + Text: {verse_text} + """) + + +# if __name__ == "__main__": + # get_verse() + +my_scheduler = sched.scheduler(time.time, time.sleep) +my_scheduler.enter(60, 1, get_verse) +my_scheduler.run() diff --git a/pull-all-verses-into-files-apibible.py b/pull-all-verses-into-files-apibible.py new file mode 100644 index 0000000..b7d9f8d --- /dev/null +++ b/pull-all-verses-into-files-apibible.py @@ -0,0 +1,175 @@ +""" +This is a one time script to pull all possible time stamped verses into a local db. +I am not sure if an ESP device would have the appropriate storage for the db, so this +branch is just for testing. As of writing this, the main file hasn't been updated to not +make API calls. +""" + +import requests +import apikey +import re +import time +import sqlite3 +import pprint + +TWELVE_HOURS = list(range(1, 12)) +TWOFOUR_HOURS = list(range(1, 25)) +MINUTES = list(range(1, 61)) +VERSION = "en-lsv" +APIKEY = apikey.APIBIBLEKEY +HEADERS = {"api-key": APIKEY} +DBCON = sqlite3.connect("./time_verse.db") +CURSOR = DBCON.cursor() +BIBLE_BOOKS = [ + "Genesis", + "Exodus", + "Leviticus", + "Numbers", + "Deuteronomy", + "Joshua", + "Judges", + "Ruth", + "1 Samuel", + "2 Samuel", + "1 Kings", + "2 Kings", + "1 Chronicles", + "2 Chronicles", + "Ezra", + "Nehemiah", + "Esther", + "Job", + "Psalm", + "Proverbs", + "Ecclesiastes", + "Song of Solomon", + "Isaiah", + "Jeremiah", + "Lamentations", + "Ezekiel", + "Daniel", + "Hosea", + "Joel", + "Amos", + "Obadiah", + "Jonah", + "Micah", + "Nahum", + "Habakkuk", + "Zephaniah", + "Haggai", + "Zechariah", + "Malachi", + "Matthew", + "Mark", + "Luke", + "John", + "Acts", + "Romans", + "1 Corinthians", + "2 Corinthians", + "Galatians", + "Ephesians", + "Philippians", + "Colossians", + "1 Thessalonians", + "2 Thessalonians", + "1 Timothy", + "2 Timothy", + "Titus", + "Philemon", + "Hebrews", + "James", + "1 Peter", + "2 Peter", + "1 John", + "2 John", + "3 John", + "Jude", + "Revelation", +] +BIBLEID = "65eec8e0b60e656b-01" + + +def get_bibles(): + url = f"https://api.scripture.api.bible/v1/bibles/{BIBLEID}/books" # /search?query=Jude 2:24" + response = requests.get(url, headers=HEADERS) + data = response.json() + pprint.pp(data) + + +def test_call(): + url = ( + f"https://api.scripture.api.bible/v1/bibles/{BIBLEID}/search?query=Exodus 13:13" + ) + response = requests.get(url, headers=HEADERS) + pprint.pp(response.json()) + query = response.json()["data"]["passages"][0]["content"] + parsed = query.split("/span>")[1][:-4] + print(parsed) + + # pass_extract = re.split(r"\[\d{1,3}\]", str(passage[0])) + # simplified = re.sub(r"(^\s|\s{2,}|\s\(ESV\)$)", "", pass_extract[1]) + # if "Footnotes" in simplified: + # new_list = re.sub(r"Footnotes.*$", "", simplified) + # new_list = new_list.replace("(1)", "") + # print(new_list) + # else: + # new_list = simplified + # simplified2 = re.sub(r"(\\n|,$)", " ", new_list) + + +# {"detail": "Request was throttled. Try again in 700 seconds."} + + +def iterate_over_books(): + count = 0 + for book in BIBLE_BOOKS: + print(f"Searching for {book}") + for hour in TWOFOUR_HOURS: + for min in MINUTES: + time.sleep(1) + count += 1 + url = f"https://api.scripture.api.bible/v1/bibles/{BIBLEID}/search?query={book} {hour}:{min}" + response = requests.get(url, headers=HEADERS) + if response.status_code == 400: + print( + "Status Code 400 - End of Chapter. Moving onto the next one." + ) + if count > 4500: + print( + f"Getting close to the end of the 5k daily limit. Cutting it off now, at the end of a book. Current location is {book} {hour}:{min}" + ) + return + break + print(f"Count: {count} and Passage: {book} {hour}:{min}") + query = response.json()["data"]["passages"][0]["content"] + simplified2 = query.split("/span>")[1][:-4] + + double_close = simplified2.count("”") + double_open = simplified2.count("“") + single_open = simplified2.count("'") + single_open = simplified2.count("‘") + single_closed = simplified2.count("’") + char_tuple = (double_open, double_close, single_open, single_closed) + if char_tuple == (1, 0, 0, 0): + simplified2 += "”" + elif char_tuple == (1, 1, 1, 0): + simplified2 += "’" + elif char_tuple == (1, 0, 1, 0): + simplified2 += "”’" + replace_apos = simplified2.replace("'", "’") + print(replace_apos) + + CURSOR.execute( + f""" + insert or replace into verses(book, chap_num, verse_num, verse_text) + values ('{book}','{hour}','{min}', '{replace_apos}') + """) + DBCON.commit() + + +if __name__ == "__main__": + # get_bibles() + test_call() + # iterate_over_books() diff --git a/pull-all-verses-into-files-crossway.py b/pull-all-verses-into-files-crossway.py new file mode 100644 index 0000000..61a6a34 --- /dev/null +++ b/pull-all-verses-into-files-crossway.py @@ -0,0 +1,166 @@ +""" +This is a one time script to pull all possible time stamped verses into a local db. +I am not sure if an ESP device would have the appropriate storage for the db, so this +branch is just for testing. As of writing this, the main file hasn't been updated to not +make API calls. +""" + +import requests +import apikey +import re +import time +import sqlite3 + +TWELVE_HOURS = list(range(1, 12)) +TWOFOUR_HOURS = list(range(1, 25)) +MINUTES = list(range(1, 61)) +VERSION = "en-lsv" +APIKEY = apikey.KEY +HEADERS = {"Authorization": APIKEY} +DBCON = sqlite3.connect('./time_verse.db') +CURSOR = DBCON.cursor() +BIBLE_BOOKS = [ + # "Genesis", + # "Exodus", + # "Leviticus", + # "Numbers", + "Deuteronomy", + "Joshua", + "Judges", + "Ruth", + "1 Samuel", + "2 Samuel", + "1 Kings", + "2 Kings", + "1 Chronicles", + "2 Chronicles", + "Ezra", + "Nehemiah", + "Esther", + "Job", + "Psalm", + "Proverbs", + "Ecclesiastes", + "Song of Solomon", + "Isaiah", + "Jeremiah", + "Lamentations", + "Ezekiel", + "Daniel", + "Hosea", + "Joel", + "Amos", + "Obadiah", + "Jonah", + "Micah", + "Nahum", + "Habakkuk", + "Zephaniah", + "Haggai", + "Zechariah", + "Malachi", + "Matthew", + "Mark", + "Luke", + "John", + "Acts", + "Romans", + "1 Corinthians", + "2 Corinthians", + "Galatians", + "Ephesians", + "Philippians", + "Colossians", + "1 Thessalonians", + "2 Thessalonians", + "1 Timothy", + "2 Timothy", + "Titus", + "Philemon", + "Hebrews", + "James", + "1 Peter", + "2 Peter",p + "1 John", + "2 John", + "3 John", + "Jude", + "Revelation", +] + +def test_call(): + url = "https://api.esv.org/v3/passage/text/?q=Exodus 9:29" + response = requests.get(url, headers=HEADERS) + print(response.text) + query = response.json()["query"] + passage = response.json()["passages"] + verse = response.json()["query"] + pass_extract = re.split(r"\[\d{1,3}\]", str(passage[0])) + simplified = re.sub(r"(^\s|\s{2,}|\s\(ESV\)$)", "", pass_extract[1]) + if "Footnotes" in simplified: + new_list = re.sub(r"Footnotes.*$", "", simplified) + new_list = new_list.replace("(1)", "") + print(new_list) + else: + new_list = simplified + simplified2 = re.sub(r"(\\n|,$)", " ", new_list) + + +# {"detail": "Request was throttled. Try again in 700 seconds."} + +def iterate_over_books(): + for book in BIBLE_BOOKS: + print(f"Searching for {book}") + for hour in TWOFOUR_HOURS: + for min in MINUTES: + time.sleep(1) + while True: + url = f"https://api.esv.org/v3/passage/text/?q={book} {hour}:{min}" + response = requests.get(url, headers=HEADERS) + if response.status_code == 429: + time_to_wait = int(re.search(r'\d+', response.text).group()) + seconds_to_wait = int(time_to_wait)+200 + print("...ZzZzZz....") + print(f"Waiting {seconds_to_wait} seconds because of rate limiting.") + print("...ZzZzZz....") + time.sleep(seconds_to_wait) + continue + break + query = response.json()["query"] + if query != f"{book} {hour}:{min}": + break + else: + print(f"{query} successfully found. Parsing and writing to file.") + passage = response.json()["passages"] + verse = response.json()["query"] + pass_extract = re.split(r"\[\d{1,3}\]", str(passage[0])) + simplified = re.sub(r"(^\s|\s{2,}|\s\(ESV\)$)", "", pass_extract[1]) + if "Footnotes" in simplified: + new_list = re.sub(r"Footnotes.*$", "", simplified) + new_list = new_list.replace("(1)", "") + else: + new_list = simplified + simplified2 = re.sub(r"(,$)", ".", new_list) + + double_close = simplified2.count("”") + double_open = simplified2.count("“") + single_open = simplified2.count("'") + single_open = simplified2.count("‘") + single_closed = simplified2.count("’") + char_tuple = (double_open, double_close, single_open, single_closed) + if char_tuple == (1, 0, 0, 0): + simplified2 += "”" + elif char_tuple == (1, 1, 1, 0): + simplified2 += "’" + elif char_tuple == (1, 0, 1, 0): + simplified2 += "”’" + print(simplified2) + CURSOR.execute( + f"insert into verses(book, chap_num, verse_num, verse_text) values ('{book}','{hour}','{min}', '{new_list}')" + ) + DBCON.commit() + + +if __name__ == "__main__": + iterate_over_books() + # test_call() diff --git a/verse-time-display.py b/verse-time-display.py deleted file mode 100644 index 122581e..0000000 --- a/verse-time-display.py +++ /dev/null @@ -1,154 +0,0 @@ -import requests -from Levenshtein import distance as lev -import time -import re -import random -from timeout import timeout -import datetime -import apikey - -VERSION = "en-lsv" -APIKEY = apikey.KEY -HEADERS = {"Authorization": APIKEY} -BIBLE_BOOKS = [ - "Genesis", - "Exodus", - "Leviticus", - "Numbers", - "Deuteronomy", - "Joshua", - "Judges", - "Ruth", - "1 Samuel", - "2 Samuel", - "1 Kings", - "2 Kings", - "1 Chronicles", - "2 Chronicles", - "Ezra", - "Nehemiah", - "Esther", - "Job", - "Psalm", - "Proverbs", - "Ecclesiastes", - "Song of Solomon", - "Isaiah", - "Jeremiah", - "Lamentations", - "Ezekiel", - "Daniel", - "Hosea", - "Joel", - "Amos", - "Obadiah", - "Jonah", - "Micah", - "Nahum", - "Habakkuk", - "Zephaniah", - "Haggai", - "Zechariah", - "Malachi", - "Matthew", - "Mark", - "Luke", - "John", - "Acts", - "Romans", - "1 Corinthians", - "2 Corinthians", - "Galatians", - "Ephesians", - "Philippians", - "Colossians", - "1 Thessalonians", - "2 Thessalonians", - "1 Timothy", - "2 Timothy", - "Titus", - "Philemon", - "Hebrews", - "James", - "1 Peter", - "2 Peter", - "1 John", - "2 John", - "3 John", - "Jude", - "Revelation", -] - - -def get_time(): - gettime = datetime.datetime.now() - time = gettime.strftime("%H:%M") - return time - - -def choose_book(): - rand_book = random.choice(BIBLE_BOOKS) - return rand_book - - -# @timeout(15) -def get_verse(): - curr_time = get_time() - extract = "" - distance = lev(extract, curr_time) - while True: - book = choose_book() - time.sleep(2) - url = f"https://api.esv.org/v3/passage/text/?q={book} {curr_time}" - response = requests.get(url, headers=HEADERS) - query = response.json()["query"] - print(query) - chap_verse = re.search(r"(\d{1,3}:\d{1,3})", query) - try: - extract = chap_verse.group(0) - except AttributeError as a: - print(a) - - distance = lev(extract, curr_time) - if "0" in curr_time and not curr_time.endswith("0"): - curr_time = curr_time.replace("0", "") - print(curr_time) - - if distance < 1: - print(f"{extract} is equal to {curr_time}!") - break - return response - - -def parse_verse(): - response = get_verse() - passage = response.json()["passages"] - verse = response.json()["query"] - pass_extract = re.split(r"\[\d{1,3}\]", str(passage[0])) - simplified = re.sub(r"(^\s|\s{2,}|\s\(ESV\)$)", "", pass_extract[1]) - simplified2 = re.sub(r"(\\n|,[a-zA-Z])", " ", simplified) - if "Footnotes" in simplified2: - new_list = simplified2.split("(1)Footnotes")[0] - new_list = new_list.replace("(1)", " ") - print(new_list) - else: - new_list = simplified2 - - double_close = new_list.count('”') - double_open = new_list.count('“') - single_open = new_list.count("'") - single_open = new_list.count("‘") - single_closed = new_list.count('’') - char_tuple = (double_open, double_close, single_open, single_closed) - if char_tuple == (1, 0, 0, 0): - new_list += '”' - elif char_tuple == (1, 1, 1, 0): - new_list += '’' - elif char_tuple == (1, 0, 1, 0): - new_list += '”’' - print(new_list) - print(verse) - - -if __name__ == "__main__": - parse_verse() diff --git a/verses b/verses new file mode 100644 index 0000000..e69de29