I'm currently builting a script for a church here in town to parse through the Bible and find select verses. I currently am using the KJV which is just in a single .txt file. Here is some sample from the text file:

1:1 In the beginning God created the heaven and the earth.

1:2 And the earth was without form, and void; and darkness was upon
the face of the deep. And the Spirit of God moved upon the face of the
waters.

I am creating the script to simply run and then I can type a verse name such as Genesis 1:1 and the verse would pop up. I currently have about 75% of the Script done. I am now having problem with the command of searching for the text. I understand that I need to use a for loop to count the index of my input (John for example) and then store that index from the abrevrBook array. I think of it as book[1] = abrevrBook[1] so if I input Genesis, you want to have the program search for gen. Here's my code:

#!/usr/bin/python

bible = {}
for line in open("KJV.txt"):
    (line, key, val) = line.split('|')
    bible[str(key.rstrip(' ').lstrip(' '))] = val.rstrip('\n').lstrip(' ')

book = ["Genesis", "Exodus", "Leviticus", "Numbers", "Deuteronomy",
"Joshua", "Judges", "Ruth", "1Samuel", "2Samuel", "1Kings",
"2Kings", "1Chronicles", "2Chronicles", "Ezra", "Nehemiah",
"Esther", "Job", "Psalms", "Proverbs", "Ecclesiastes",
"Songs", "Isaiah", "Jeremiah", "Lamentations", "Ezekiel",
"Daniel", "Hosea", "Joel", "Amos", "Obadiah", "Jonah",
"Micah", "Nahum", "Habakkuk", "Zephaniah", "Haggai", "Zechariah",
"Malachi", "Matthew", "Mark", "Luke", "John", "Acts", "Romans",
"1Corinthians", "2Corinthians", "Galatians", "Ephesians",
"Phillipians", "Colossians", "1Thessalonians", "2Thessalonians",
"1Timothy", "2Timothy", "Titus", "Philemon", "Hebrews", "James",
"1Peter", "2Peter", "1John", "2John", "3John", "Jude", "Revelation" ]
abrevBook = ["gen", "exo", "lev", "num", "deu", "jos", "jdg",
"rut", "1sa", "2sa", "1ki", "2ki", "1ch", "2ch",
"ezr", "neh", "est", "job", "psa", "pro", "ecc",
"son", "isa", "jer", "lam", "eze", "dan", "hos",
"joe", "amo", "oba", "jon", "mic", "nah", "hab",
"zep", "hag", "zec", "mal", "mat", "mar", "luk",
"joh", "act", "rom", "1co", "2co", "gal", "eph",
"phi", "col", "1th", "2th", "1ti", "2ti", "tit",
"phl", "heb", "jam", "1pe", "2pe", "1jo", "2jo",
"3jo", "jud", "rev"]

So, I know I need to store my search term (gen 1:1) in a string (or array) so that I can get

if bible.has_key(search):
stringToOutput = bible.get(search)

I'm confused on how to get this part done though. Thank you in advance.

In the sample text you provided there is no "|" charachter. You base your split on it. How and why?
I would have written the program for you, if I had found the kjv.txt in the format you mentioned by quick googling. All I found was this: http://www.bibleprotector.com/TEXT-PCE.zip , which has different book naming. Can you provide a link for it?
The fifth line in the code is bogous. Has this ever worked?
I could not figure out, what the expected behavior of the program is.

Anyway, with the input mentioned above the searching would be on python2:

#http://www.bibleprotector.com/TEXT-PCE.zip


print "indexing..."

indexdict=dict()
with open("TEXT-PCE.txt") as f:
    countbytes=0
    for line in f:
        fields= line[:8].split()
        book=fields[0].strip().upper()
        chapter,verse=map(str.strip,fields[1].split(":"))
        indexdict[(book,chapter,verse)]=countbytes
        countbytes+=len(line)

print "indexing done"

f=open("TEXT-PCE.txt")
while True:
    search=raw_input("enter book, chapter and verse separated by comma, or press Q for exit\n")
    if search=="Q": break
    book,chapter,verse=map(str.strip,search.split(","))
    key=(book.upper(),chapter,verse)
    if key in indexdict:
        f.seek(indexdict[key])
        l=f.readline()
        print l
f.close()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.