python - How to sort through a bible.txt by entering the name, verse etc.? -


here criteria:

  1. get copy of text of whole bible

  2. this should ready open, read, split fields

  3. use create persistent dictionary variable called bible

  4. set python program when type have shown, program know entered on command line. not have prompt words.

  5. parse reference meaning book, chapter, start verse , end verse. other variations rev 1:1, rev 12, or rev 10:1-3

  6. when prints have output limit width of 100 characters wide before wrapping new line, should indent enough have reference shown on left , spaces , text aligned on right.

the text in text file looks this:

0 | gen 1:1 | in beginning god created heaven , earth.  1 | gen 1:2 | , earth without form, , void; , darkness upon face of deep. , spirit of god moved upon face of waters.  2 | gen 1:3 | , god said, let there light: , there light.  

my code far looks this:

import os import sys import re  word_search = raw_input(r'enter word search: ') book = open("kjv.txt", "r") first_lines = {36: 'genesis', 4812: 'exodus', 8867: 'leviticus', 11749: 'numbers', 15718: 'deuteronomy',            18909: 'joshua', 21070: 'judges', 23340: 'ruth', 23651: 'i samuel', 26641: 'ii samuel',            29094: 'i kings', 31990: 'ii kings', 34706: 'i chronicles', 37378: 'ii chronicles',            40502: 'ezra', 41418: 'nehemiah', 42710: 'esther', 43352: 'job', 45937: 'psalms', 53537: 'proverbs',            56015: 'ecclesiastes', 56711: 'the song of solomon', 57076: 'isaih', 61550: 'jeremiah',            66480: 'lamentations', 66961: 'ezekiel', 71548: 'daniel' }   ln, line in enumerate(book):      if word_search in line:          first_line = max(l l in first_lines if l < ln)          bibook = first_lines[first_line]           template = "\nline: {0}\nstring: {1}\nbook:\n"          output = template.format(ln, line, bibook)          print output 

i know pretty messed up, please straighten me out.

a summary of think doing:

create dictionary text file, somehow user input chapter , verse, , have program able spit chapter , verses out.

edit:

import csv import string  reader = csv.reader(open('bible.txt','rb'),delimiter="|") bible = dict()  line in reader:     chapter = line[1].split()[0]     key = line[1].split()[1]     linenum = line[0].strip()     bible[chapter] = bible.get(chapter,dict())     bible[chapter].update({key:line[2],linenum:line[2]})  entry = raw_input('entry?') key = '' chapter = ""  char in entry:     if char in string.letters:         chapter += char.lower()     elif char in map(str,range(10)):         key += char     else:         key += ":"  print "looking in chapter", chapter print "looking for", key  try:     print bible[chapter][key] except keyerror:     print "this passage not in dictionary." 

when executed:

>python bible.py entry?:gen1-1 in beginning god created heaven , earth  >python bible.py entry?:gen0 in beginning god created heaven , earth  >python bible.py entry?:gen1:1 in beginning god created heaven , earth. 

as long numbers separated that's not number, input work correctly , converted #:#:#. can use either chapter-pagenum or chapter-key


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -