#coding: utf-8
import workflow
import re
import console
action_in = workflow.get_input()
bible = [
    ['Es'],
    ['Génesis', 'Gé', 'Ge', 'Gé', 'Gene', 'Gen', 'Gén', 'Génesis'],
    ['Éxodo', 'Éx', 'Ex', 'Exodo', 'Exo'],
    ['Levítico', 'Le', 'Lev', 'Levítico', 'Levitico'],
    ['Números', 'Nú', 'Nu', 'Num', 'Numeros'],
    ['Deuteronomio', 'Dt', 'Deu', 'De'],
    ['Josué', 'Jos', 'Josue'],
    ['Jueces', 'Jue'],
    ['Rut', 'Ru'],
    ['1 Samuel', '1Sa', '1 Sam'],
    ['2 Samuel', '2Sa', '2 Sam'],
    ['1 Reyes', '1Re', '1 Rey'],
    ['2 Reyes', '2Re', '2 Rey'],
    ['1 Crónicas', '1Cr', '1 Cro', '1 Cr'],
    ['2 Crónicas', '2Cr', '2 Cro', '2 Cr'],
    ['Esdras', 'Esd'],
    ['Nehemías', 'Ne', 'Neh'],
    ['Ester', 'Est'],
    ['Job', 'Job'],
    ['Salmos', 'Sl', 'Sal', 'Salmo'],
    ['Proverbios', 'Pr', 'Pro', 'Prov'],
    ['Eclesiastés', 'Ec', 'Ecl', 'Ecle'],
    ['El Cantar de los Cantares', 'Can', 'Cantar', 'Cantar de los Cantares'],
    ['Isaías', 'Isaías', 'Isaias', 'Isa', 'Is'],
    ['Jeremías', 'Jeremías', 'Jeremias', 'Jere', 'Jer'],
    ['Lamentaciones', 'Lam', 'Lament'],
    ['Ezequiel', 'Eze', 'Ezeq'],
    ['Daniel', 'Da', 'Dan'],
    ['Oseas', 'Os', 'Ose'],
    ['Joel', 'Joe'],
    ['Amós', 'Am', 'Amos'],
    ['Abdías', 'Abd', 'Abdias'],
    ['Jonás', 'Jon', 'Jonas'],
    ['Miqueas', 'Miq', 'Miquea'],
    ['Nahúm', 'Na', 'Nah'],
    ['Habacuc', 'Hab', 'Haba'],
    ['Sofonías', 'Sof', 'Sofonias'],
    ['Ageo', 'Ag', 'Age'],
    ['Zacarías', 'Zac', 'Zacarias'],
    ['Malaquías', 'Mal', 'Malaquias'],
    ['Mateo', 'Mt', 'Mat'],
    ['Marcos', 'Mr', 'Marc', 'Mar'],
    ['Lucas', 'Lu', 'Luc'],
    ['Juan', 'Jn'],
    ['Hechos', 'Hch', 'Hech'],
    ['Romanos', 'Ro', 'Rom'],
    ['1 Corintios', '1Co', '1 Cor'],
    ['2 Corintios', '2Co', '2 Cor'],
    ['Gálatas', 'Gál', 'Galatas', 'Gal'],
    ['Efesios', 'Ef', 'Efe'],
    ['Filipenses', 'Flp', 'Fili'],
    ['Colosenses', 'Col', 'Colo'],
    ['1 Tesalonicenses', '1Te', '1 Te', '1 Tes'],
    ['2 Tesalonicenses', '2Te', '2 Te', '2 Tes'],
    ['1 Timoteo', '1Ti', '1 Ti', '1 Tim'],
    ['2 Timoteo', '2Ti', '2 Ti', '2 Tim'],
    ['Tito', 'Tit'],
    ['Filemón', 'Flm', 'File', 'Filemon'],
    ['Hebreos', 'Heb', 'Hebr'],
    ['Santiago', 'Snt', 'Sant'],
    ['1 Pedro', '1Pe', '1 Ped', '1 Pe'],
    ['2 Pedro', '2Pe', '2 Ped', '2 Pe'],
    ['1 Juan', '1Jn', '1 Jn'],
    ['2 Juan', '2Jn', '2 Jn'],
    ['3 Juan', '3Jn', '3 Jn'],
    ['Judas', 'Jud'],
    ['Revelación', 'Rev', 'Revelacion', 'Revel', 'Re']
]
def getBook(book):
	for list in bible:
		for bookName in list:
			if bookName.lower().strip() == book.lower().strip():
				return (list[0], list[1])
	return ('', '')
	
def processMatch(m):
	part = ''
	book = ''
	abreviation = ''
	chapter = ''
	verses = '';
	if m.group(2) is not None:
		part = m.group(2).strip()
	if m.group(3) is not None:
		book = m.group(3).strip()
	if m.group(4) is not None:
		chapter = m.group(4).strip()
	if m.group(5) is not None:
		verses = m.group(5).strip()
	(libro, abreviation) = getBook(part + " " + book)
	
	if m.group(1) is not None:
		if m.group(1).strip() == '[':
			return false
		elif m.group(1).strip() == '=':
			return false
		else:
			return '[{0} {1}:{2}](equipdbible://x-callback-url/lookup?x-source=editorial&language=es&scripture={3}{4}:{5}&x-success=editorial://)'.format(libro.strip(), chapter.strip(), verses, abreviation.strip(), chapter.strip(),verses.strip().replace(' ', ''))
	else:
		return '[{0} {1}:{2}](equipdbible://x-callback-url/lookup?x-source=editorial&language=es&scripture={3}{4}:{5}&x-success=editorial://)'.format(libro.strip(), chapter.strip(), verses, abreviation.strip(), chapter.strip(),verses.strip().replace(' ', ''))
#This regular expression matches a bible scripture capturing 
#Group 1 ([ = or Empty) - This char help identify when a scripture has already been extracted and replaced in the text as a markdown link to equipd bible.
#Group 2 (Primero, segundo or tercero) (o vacío)
#Group 3 (Libro de la Biblia)
#Group 4 (Capítulo)
#Group 5 (Versículo/s)
regex = re.compile(r'([\[=])?([1-3])?(?:\s*)([\w+]{2,})[.]?(?:\s*)(\d+)(?:\s*)[:]((?:\s*)(?:\d+)(?:(?:[,;:–-])?(?:\s*)(?:\d+)?)*)', re.UNICODE)
result = regex.sub(processMatch, action_in)
workflow.set_output(result)
There are no comments yet.