8000 GitHub - obrhubr/xword-converter: Python library to convert crossword puzzles into different formats.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

obrhubr/xword-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

XWORD - Converter


Warning: It currently does not handle the .puz checksums and thus the output could be interpreted as invalid by some programs.


This is a python library that is able to parse and serialize different crossword puzzle formats.

The three formats currently supported are:

  • .puz, the Across Lite format (binary)
  • .json, as used by the NYT (detailed here)
  • .json, full internal data as represented internally in the library

Installing

Run the following command in this folder to install it: pip install .

Usage

There are two main ways to use the program. You can either import directly from file and export the converted puzzle to a file again, or use the parsed Puzzle class to analyse and extract data from the puzzle for your own needs.

Importing and Exporting a puzzle

import xword_converter as xword

converter = xword.Converter()

# Import the puzzle to a Puzzle  object from a file
puzzle = converter.import_puzzle("puzzle.puz", "puz")
# And write the Puzzle object to file again
converter.export_puzzle(puzzle, "puzzle.json", "json")

The Puzzle object that is the output of parsing and serializing looks like this has the following attributes:

{
    "grid": [
        "M",
        "E",
        "T",
        "R",
        "O",
		"Rest of the grid's squares..."
    ],
    "across_clues": [
        {
            "x": 0,
            "y": 0,
            "label": 1,
            "clue": "",
            "word": "METRO",
            "squares": [
                0,
                1,
                2,
                3,
                4
            ],
            "related_clues": []
        }
    ],
    "down_clues": [
        {
            "x": 0,
            "y": 0,
            "label": 1,
            "clue": "",
            "word": "TRAMS",
            "squares": [
                0,
                5,
                10,
                15
            ],
            "related_clues": []
        }
    ],
    "dimensions": [
        5,
        5
    ],
    "metadata": {
        "title": "Crossword puzzle",
        "author": "obrhubr",
        "copyright": "Copyright notice",
        "notes": {
            "note": "This is a note."
        }
    }
}

About

Python library to convert crossword puzzles into different formats.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

0