fetchbible.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #!/usr/bin/python
  2. import sys, os
  3. import urllib, urllib2
  4. import re
  5. books = [
  6. "Genesis",
  7. "Exodus",
  8. "Leviticus",
  9. "Numbers",
  10. "Deuteronomy",
  11. "Joshua",
  12. "Judges",
  13. "Ruth",
  14. "1 Samuel",
  15. "2 Samuel",
  16. "1 Kings",
  17. "2 Kings",
  18. "1 Chronicles",
  19. "2 Chronicles",
  20. "Ezra",
  21. "Nehemiah",
  22. "Esther",
  23. "Job",
  24. "Psalms",
  25. "Proverbs",
  26. "Ecclesiastes",
  27. "Song of Songs",
  28. "Isaiah",
  29. "Jeremiah",
  30. "Lamentations",
  31. "Ezekiel",
  32. "Daniel",
  33. "Hosea",
  34. "Joel",
  35. "Amos",
  36. "Obadiah",
  37. "Jonah",
  38. "Micah",
  39. "Nahum",
  40. "Habakkuk",
  41. "Zephaniah",
  42. "Haggai",
  43. "Zechariah",
  44. "Malachi",
  45. "Matthew",
  46. "Mark",
  47. "Luke",
  48. "John",
  49. "Acts",
  50. "Romans",
  51. "1 Corinthians",
  52. "2 Corinthians",
  53. "Galatians",
  54. "Ephesians",
  55. "Philippians",
  56. "Colossians",
  57. "1 Thessalonians",
  58. "2 Thessalonians",
  59. "1 Timothy",
  60. "2 Timothy",
  61. "Titus",
  62. "Philemon",
  63. "Hebrews",
  64. "James",
  65. "1 Peter",
  66. "2 Peter",
  67. "1 John",
  68. "2 John",
  69. "3 John",
  70. "Jude",
  71. "Revelation"
  72. ]
  73. chapters = {
  74. "Genesis": 50,
  75. "Exodus": 40,
  76. "Leviticus": 27,
  77. "Numbers": 36,
  78. "Deuteronomy": 34,
  79. "Joshua": 24,
  80. "Judges": 21,
  81. "Ruth": 4,
  82. "1 Samuel": 31,
  83. "2 Samuel": 24,
  84. "1 Kings": 22,
  85. "2 Kings": 25,
  86. "1 Chronicles": 29,
  87. "2 Chronicles": 36,
  88. "Ezra": 10,
  89. "Nehemiah": 13,
  90. "Esther": 10,
  91. "Job": 42,
  92. "Psalms": 150,
  93. "Proverbs": 31,
  94. "Ecclesiastes": 12,
  95. "Song of Songs": 8,
  96. "Isaiah": 66,
  97. "Jeremiah": 52,
  98. "Lamentations": 5,
  99. "Ezekiel": 48,
  100. "Daniel": 12,
  101. "Hosea": 14,
  102. "Joel": 3,
  103. "Amos": 9,
  104. "Obadiah": 1,
  105. "Jonah": 4,
  106. "Micah": 7,
  107. "Nahum": 3,
  108. "Habakkuk": 3,
  109. "Zephaniah": 3,
  110. "Haggai": 2,
  111. "Zechariah": 14,
  112. "Malachi": 4,
  113. "Matthew": 28,
  114. "Mark": 16,
  115. "Luke": 24,
  116. "John": 21,
  117. "Acts": 28,
  118. "Romans": 16,
  119. "1 Corinthians": 16,
  120. "2 Corinthians": 13,
  121. "Galatians": 6,
  122. "Ephesians": 6,
  123. "Philippians": 4,
  124. "Colossians": 4,
  125. "1 Thessalonians": 5,
  126. "2 Thessalonians": 3,
  127. "1 Timothy": 6,
  128. "2 Timothy": 4,
  129. "Titus": 3,
  130. "Philemon": 1,
  131. "Hebrews": 13,
  132. "James": 5,
  133. "1 Peter": 5,
  134. "2 Peter": 3,
  135. "1 John": 5,
  136. "2 John": 1,
  137. "3 John": 1,
  138. "Jude": 1,
  139. "Revelation": 22
  140. }
  141. apikey = urllib.quote_plus("d4a7410cbf1fcf4c4d4ba52a460c6458")
  142. bible = "KJV1900"
  143. formattype = ".txt"
  144. baseurl = "http://api.biblia.com/v1/bible/content/"
  145. #qstring = urllib.quote_plus(sys.argv[1])
  146. #url = baseurl + bible + formattype + "?key=" + apikey + "&passage=" + qstring + "&style=oneVersePerLine"
  147. rqurl = baseurl + bible + formattype + "?key=" + apikey + "&style=oneVersePerLine&passage="
  148. #text = urllib2.urlopen(url).read()
  149. for book in books:
  150. bfilename = re.sub(" ", "-", book.lower()) + ".tex"
  151. bookfile = open(bfilename, "w")
  152. bookfile.write("\\book{" + book + "}")
  153. for chap in range(1, chapters[book]):
  154. cfile = re.sub(" ", "-", book.lower()) + str(chap)
  155. cfilename = cfile + ".tex"
  156. bookfile.write("\\input " + cfile)
  157. q = rqurl + urllib.quote_plus(book + " " + str(chap))
  158. text = urllib2.urlopen(q).read()
  159. text = re.sub(r'^[0-9]+', "\\verse ", text)
  160. text = re.sub(r'.* (KJV 1900)', "\\chapter", text)
  161. chapfile = open(cfilename, "w")
  162. chapfile.write(text)
  163. chapfile.close()
  164. bookfile.close()