Skip to content

Instantly share code, notes, and snippets.

@epramono
Last active July 26, 2021 22:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epramono/9446027 to your computer and use it in GitHub Desktop.
Save epramono/9446027 to your computer and use it in GitHub Desktop.
This action will convert the Bible verse into a YouVersion's Bible app. Four output modes are available, requiring Day One, 1Writer, and Launch Center Pro.
# -*- coding: utf-8 -*-
import sys
import urllib
import webbrowser
import re
# dictionary for uncommon OSIS codes
books = { "Judges" : "JDG", "1 Samuel" : "1SA", "2 Samuel" : "2SA", "1 Kings" : "1KI", "2 Kings" : "2KI", "1 Chronicles" : "1CH", "2 Chronicles" : "2CH", "Song of Solomon" : "SNG", "Ezekiel" : "EZK", "Joel" : "JOL", "Nahum" : "NAM", "Mark" : "MRK", "John" : "JHN", "1 Corinthians" : "1CO", "2 Corinthians" : "2CO", "1 Thessalonians" : "1TH", "2 Thessalonians" : "2TH", "1 Timothy" : "1TI", "2 Timothy" : "2TI", "Philippians" : "PHP", "Philemon" : "PHM", "James" : "JAS", "1 Peter" : "1PE", "2 Peter" : "2PE", "1 John" : "1JN", "2 John" : "2JN", "3 John" : "3JN" }
# extract the verse reference
ov = sys.argv[1]
bracket = ov.index('(')
trailing = ov[(bracket-1):]
t = trailing.replace(', ',',')
list = t.split(" ")
# parse for 'Book C:V Translation'
count = len(list)
print(list)
if (count == 5):
book = list[1][1:] + ' ' + list[2]
else:
book = list[1][1:]
# remove the weird characters
book = book[3:len(book)-3]
cv = list[count-2]
translation = list[count-1][:3]
# convert to OSIS code
shortbook = book[:5].replace(' ','')
b = books.get(book, shortbook[:3].upper())
chve = cv.split(':')
chapter = chve[0]
verse = chve[1]
# remove the weird characters
chapter = chapter[3:len(chapter)-3]
verse = verse[3:len(verse)-3]
# 1-3
# 20,22-24
# 18-20,25
# 1-3,5-7,9-11,13,14
while (verse.find('-') >= 0):
lr = verse.split('-')
left = int(lr[0].split(',')[-1])
right = int(lr[1].split(',')[0])
r = ''
for n in range(left, right):
r += str(n) +','
verse = verse.replace (str(left) + '-', r)
# 17
# 17,18,20,21,22
if (verse.find(',') >= 0):
verses = verse.split(',')
else:
verses = [verse]
# BOOK.Chapter.Verse+..
refs = ''
for n in verses:
refs += '+' + b + '.' + chapter + '.' + n
urlscheme = 'youversion://bible?reference=' + refs[1:]
# prepare Markdown [ref](url) format
# uv = (book + ' ' + cv + ' ' + translation).replace(',', ', ')
md = '[' + trailing[1:] + '](' + urlscheme + ')'
result = ov.replace(trailing, md)
# 1. New MD Entry in Day One
# 2. Append Sermon Notes in 1Writer
# 3. Send as iMessage (with content)
# 4. Send as iMessage (URL only)
mode = int(sys.argv[2])
encodedscheme = urllib.quote(urlscheme)
if (mode == 1):
url = 'dayone://post?entry=' + urllib.quote(result)
elif (mode == 2):
url = 'onewriter://x-callback-url/append?path=Documents&name=Sermon%20Notes.md&type=local&text=%0A' + urllib.quote('_' + result + '_\n')
elif (mode == 3):
url = 'launch://x-callback-url/messaging?body=' + urllib.quote(ov + '\n\n' + urlscheme) + '&x-success=' + encodedscheme
else:
url = 'launch://x-callback-url/messaging?body=' + urllib.quote(book + ' ' + cv + '\n\nLink: ' + urlscheme) + '&x-success=' + encodedscheme
webbrowser.open(url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment