Advertisement
acclivity

pyProcessBibleBooks

Apr 1st, 2022
1,282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. # Read Directory to get list of text files
  2.  
  3. import os
  4.  
  5. numdict = {"1": "One", "2": "Two", "3": "Three", "4": "Four", "5": "Five", "6": "Six",
  6.            "7": "Seven", "8": "Eight", "9": "Nine", "14": "Fourteen", "150": "One Hundred and Fifty"}
  7.  
  8.  
  9. def num2word(s):            # Replace this test function with your complete number-to-word process
  10.     return numdict[s]
  11.  
  12.  
  13. cwdir = os.getcwd()
  14.  
  15. dirlist = os.listdir()
  16.  
  17. print(dirlist)
  18.  
  19. for fname in dirlist:
  20.     if fname.lower().endswith(".txt"):
  21.         if fname.lower().endswith("-new.txt"):
  22.             continue
  23.         fin = open(fname)
  24.         fsplit = fname.split(".")
  25.         fout = open(fsplit[0] + "-new.txt", 'w')
  26.         for x, fline in enumerate(fin):
  27.             fline = fline.strip()
  28.             lsplit = fline.split()
  29.             if x == 0:
  30.                 book = ""
  31.                 if lsplit[0].isdigit():
  32.                     if lsplit[0] == "1":
  33.                         book = "First "
  34.                     if lsplit[0] == "2":
  35.                         book = "Second "
  36.                     if lsplit[0] == "3":
  37.                         book = "Third "
  38.                     lsplit = lsplit[1:]
  39.                 book += lsplit[0]
  40.                 book += " "
  41.                 book += num2word(lsplit[1])
  42.                 fout.write(book + "\n")
  43.                 print("\n" + book)
  44.                 continue
  45.             verse = "Verse " + num2word(lsplit[0])
  46.             verse += " "
  47.             verse += " ".join(lsplit[1:])
  48.             fout.write(verse + "\n")
  49.             print(verse)
  50.         fout.close()
  51.         fin.close()
  52.        
  53.        
  54. # Output:
  55. #
  56. # First Corinthians Fourteen
  57. # Verse One Pursue love , yet ..
  58. # Verse Two For one who speaks ..
  59. # Verse Three But one who ..
  60. #
  61. # Acts One
  62. # Verse One The first account I composed..
  63. # Verse Two two until the day when..
  64. # Verse Three To these He also..
  65. #
  66. # Psalm One Hundred and Fifty
  67. # Verse One Praise the LORD ! Praise ..
  68. # Verse Two Praise Him for..
  69. # Verse Three Praise Him..
  70.  
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement