Package: crossword
crossword=========.. image:: https://pypip.in/version/crossword/badge.svg:target: https://pypi.python.org/pypi/crossword/:alt: Latest Version.. image:: https://pypip.in/download/crossword/badge.svg:target: https://pypi.python.org/pypi/crossword/:alt: Downloads.. image:: https://pypip.in/py_versions/crossword/badge.svg:target: https://pypi.python.org/pypi/crossword/:alt: Supported Python versions.. image:: https://pypip.in/license/crossword/badge.svg:target: https://pypi.python.org/pypi/crossword/:alt: LicensePython library for handling crossword puzzles. This library provides a canonical data structurethat can be used to represent crosswords in your application. It provides a Pythonic way toperform common operations on the grid, the words and the clues of the puzzle.The library is intended for American crossword style puzzles, such as the New York Timescrossword, though variations within reason will also be supported.The library handles reading and writing the following files:* Across Lite .puz files* ipuz .ipuz filesInstallation------------You can install using pip:.. code-block:: bash$ pip install crosswordCreating and modifying crosswords---------------------------------You can create a crossword:.. code:: pythonfrom crossword import Crosswordpuzzle = Crossword(15, 15)You can iterate over rows and cells:.. code:: pythonfor row in puzzle:for cell in row:passYou also iterate using 'cells' (left-to-right, top-to-bottom):.. code:: pythonfor x, y in puzzle.cells:print(puzzle[x, y])You can store cell content by using attributes such as 'cell' and 'solution':.. code:: pythonpuzzle[x, y].cell = " "puzzle[x, y].solution = "A"puzzle[x, y].style = {'background-color': 'red'}You can access a metadata attribute:.. code:: pythoncreator = puzzle.meta.creatorEach puzzle has the attributes specified in the Dublin Core Metadata Element Set,Version 1.1, which include creator, date, description, identifier and title. By defaultthese attributes have the value None.You can iterate over metadata:.. code:: pythonfor key, value in puzzle.meta():print(key, value)You can set a clue for an entry:.. code:: pythonpuzzle.clues.across[1] = "This is a clue"puzzle.clues.down[2] = "This is a clue"You can iterate over all clues (first Across, then Down):.. code:: pythonfor direction, number, clue in puzzle.clues.all():print(direction, number, clue)You can iterate over clues in a particular direction:.. code:: pythonfor number, clue in puzzle.clues.across():print(number, clue)for number, clue in puzzle.clues.down():print(number, clue)By default these functions iterate over the clues by numerical orderof the specified clue numbers. If you wish to iterate over the clues in theorder that they were inserted you can specify sort=None:.. code:: pythonpuzzle.clues.all(sort=None)You can also specify a function yourself that will be used for sorting:.. code:: pythonpuzzle.clues.all(sort=lambda entry: ...)You can use the following attributes as dictionaries (e.g., for conversion to JSON):.. code:: pythonpuzzle.content (the cells, clues and metadata in one dictionary)puzzle.cluespuzzle.clues.acrosspuzzle.clues.downpuzzle.metaYou can use the following constants for values that represent block cells and empty cells:.. code:: pythonpuzzle.blockpuzzle.emptyA value of None may indicate that the default value is used (e.g., "#" for blocks in.ipuz puzzles).Reading and writing crosswords------------------------------You can read a crossword from an .ipuz file using:.. code:: pythonwith open('puzzle.ipuz') as puzzle_file:ipuz_dict = ipuz.read(puzzle_file.read())  # may raise ipuz.IPUZExceptionpuzzle = crossword.from_ipuz(ipuz_dict)This requires the "ipuz" package to be installed: https://pypi.python.org/pypi/ipuz.You can write a crossword to an .ipuz file using:.. code:: pythonipuz_dict = crossword.to_ipuz(puzzle)with open('puzzle.ipuz', 'w') as puzzle_file:puzzle_file.write(ipuz.write(ipuz_dict))Contributing------------Contributions are very welcome. If you've found an issue or if you'd like tosuggest a feature please open a ticket at: https://github.com/svisser/crossword/issues.You should create a virtual environment first before installing thepackages as described below. This keeps the dependencies separate from other Python packageson your system. See: https://pypi.python.org/pypi/virtualenv and, optionally,https://pypi.python.org/pypi/virtualenvwrapper.You can install the packages needed for developing and testing this library by running:.. code-block:: bash$ pip install -r dev-requirements.txtThere are also various tests included. You can run these with:.. code-block:: bash$ toxThis will run the tests in various Python versions to ensure that the libraryworks properly in each of them.Ideas for new features----------------------* Add support for Crossword Compiler .ccw files (http://crossword-compiler.com)* Add support for CrossDown .xwd files (http://www.crossdown.com/)* Add support for XPF files (http://www.xwordinfo.com/XPF/)