Git Product home page Git Product logo

sword-to-json's Introduction

SWORD to JSON – Generate json files of many Bible versions

The SWORD project provides modules freely for many different Bibles in many different languages. Often, Bible versions are provided in ways that are not convenient for developers to access. pysword is a Python package that provides an easy way to read the Bible modules from SWORD as part of your Python program.

This project leverages pysword to generate a json file from a SWORD module. As Bible translations are available in dozens of languages, this provides an easy way to generate a json version of many different Bible versions. An example is included in the project of the public domain KJV version in kjv.json.

As an example, here is the first part of the Bible so that you can see how the file is formatted.

{
    "books": [
        {
            "name": "Genesis",
            "chapters": [
                {
                    "chapter": 1,
                    "verses": [
                        {
                            "chapter": 1,
                            "text": "In the beginning God created the heaven and the earth.",
                            "verse": 1,
                            "name": "Genesis 1:1"
                        },

How to generate

Currently, due to pysword limitations, only Bible modules are supported, not dictionaries and commentaries. Additionally, this project only supports generating a json file that contains all of the text of the Old and New Testaments of a given Bible module.

First, you will need to install pysword. This can be done using pip: pip install pysword

Next, you can run using this format: python sword_to_json.py --source_file KJV.zip --bible_version KJV --output_file new.json

  • source_file – Location of the zipped module you are trying to read. You can pass the filename if you're in the same directory or you can also pass a relative or absolute folder path.
  • bible_version – Name of the module you are trying to load, as a SWORD module can include more than one Bible version. If you get the module from the SWORD project's index, the Name column has what you can pass in here.
  • output_file – Location of the json file to be written to disk. As with the source file, you can pass the filename if you're in the same directory or you can also pass a relative or absolute folder path.

Note: It can take up to a few minutes to generate the json for any given Bible version. It takes approximately one minute to run on my machine.

sword-to-json's People

Contributors

laurajauch avatar wasdin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sword-to-json's Issues

Error with ESV2011

Hey Jake, just recently found your project that uses pysword to generate JSON from the sword files. I ran into this error and wondered if you'd seen it before? I'm going to download the pysword code and see what I can find, but thought I'd also ask, just in case it was a known issue.

I am using Python 3.7.1, just in case that has bearing, but I tried it in Python 2.7 as well. I'm running a virtualenv to do this.

Sorry forgot to note. I had to install the package future. Not trying to be a pain, but a requirements.txt file for your required libs, which is only 2, but that way you could keep a list and people could just pip install -r requirements.txt.

Anyway, thank you so much for this project. I greatly appreciate seeing these out there. The digital Bible is just as powerful as the paper Bible. Still the Word of God!

ANYWAY! So here is the bug I ran into. Like I said, I'm also going to start with seeing where it is failing in pysword.

  • python sword_to_json.py --source_file ./modules/ESV2011/ESV2011.zip --bible_version ESV2011 --output_file ./modules/ESV2011/esv2011.json

Traceback (most recent call last):
File "sword_to_json.py", line 56, in
if name == "main": main()
File "sword_to_json.py", line 53, in main
bible_dict = generate_dict(args.source_file, args.bible_version)
File "sword_to_json.py", line 27, in generate_dict
'text': bible.get(books=[book.name], chapters=[chapter], verses=[verse])
File "/Users/rkeyes/git/personal/SWORD-to-JSON/venv/lib/python3.7/site-packages/pysword/bible.py", line 208, in get
output.extend(list(self.get_iter(books=books, chapters=chapters, verses=verses, clean=clean)))
File "/Users/rkeyes/git/personal/SWORD-to-JSON/venv/lib/python3.7/site-packages/pysword/bible.py", line 189, in get_iter
text = self._text_for_index(testament, idx)
File "/Users/rkeyes/git/personal/SWORD-to-JSON/venv/lib/python3.7/site-packages/pysword/bible.py", line 334, in _text_for_index
uncompressed_text = self._uncompressed_text(testament, buf_num)
File "/Users/rkeyes/git/personal/SWORD-to-JSON/venv/lib/python3.7/site-packages/pysword/bible.py", line 355, in _uncompressed_text
return zlib.decompress(compressed_data)
zlib.error: Error -3 while decompressing data: incorrect header check

Error message: No module named 'past'

Can you help me in that error??

$ python3 sword_to_json.py --source_file Nave.zip --bible_version Nave --output_file nave.json

And it returns me:

Traceback (most recent call last):
File "sword_to_json.py", line 5, in
from past.builtins import xrange
ModuleNotFoundError: No module named 'past'

What can I do?

Testament pointer breakdown in some translations.

Hi, thanks for this little handy script!

I noticed when doing a bulk build of all the Bibles that the testament combination is not working that well on line 13 so I would suggest the following fix

# load the list of books per/testament
testaments = bible_mod.get_structure()._books
# merge the books
books = []
for testament in testaments:
    books += testaments[testament]

This way it working even if there is not new or old testament books in the translation.

I have forked the repo and will be using it to setup a major update to the old getBible v1 API so not all the changes is that practical (since I am trying to hold to some v1 conventions), but if I run into any other issue I will be sure to let you know.

Error using script

Hello.

I'm not much of a Python user, so I don't really know how to proceed and fix this problem.

The issue is that after installing pysword via pip3 install pysword this is what happens after cloning the repository and trying to use the script:

$python3 sword_to_json.py --source_file KJV.zip --bible_version KJV --output_file KJVNew.json
Traceback (most recent call last):
  File "/Users/michael/Downloads/Bibles/SWORD-to-JSON/sword_to_json.py", line 5, in <module>
    from past.builtins import xrange
ModuleNotFoundError: No module named 'past'

I tried removing these two lines:

if sys.version_info > (3, 0):
    from past.builtins import xrange

But that only made things worse:

$python3 sword_to_json.py --source_file KJV.zip --bible_version KJV --output_file KJVNew.json
Traceback (most recent call last):
  File "/Users/michael/Downloads/Bibles/SWORD-to-JSON/sword_to_json.py", line 54, in <module>
    if __name__ == "__main__": main()
  File "/Users/michael/Downloads/Bibles/SWORD-to-JSON/sword_to_json.py", line 51, in main
    bible_dict = generate_dict(args.source_file, args.bible_version)
  File "/Users/michael/Downloads/Bibles/SWORD-to-JSON/sword_to_json.py", line 18, in generate_dict
    for chapter in xrange(1, book.num_chapters+1):
NameError: name 'xrange' is not defined. Did you mean: 'range'?

That's when I decided to open this incident...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.