The LitBit website generates small poems using random lines of text from classic literature.
Using public domain books from Project Gutenberg, LitBit looks for similarly sized lines of text and randomly selects 3 lines to print out as a poem.
Although the text is entirely derivative, the poem is a new, unique creation and can have meaning entirely separate from the original source.
Technologies: Flask, Python, HTML5, CSS3
Each book used on the website is processed using a Python script which reads the plain text file line by line and groups them by the number of syllables.
The number of syllables are estimated using the countsyl.py script which uses a few simple rules to determine the number of syllables. The syllable count isn't perfectly accurate, but works as a way of comparing similarly sized lines. The lines are also sanitized to remove extra whitespaces and quotation or other marks that don't have a matching symbol (for example, when a quotation starts on one line and ends on another).
The list of lines grouped by syllable count is saved in
.json format and the
books.json file is updated with each processed book's author, title, and image.
When the user visits LitBit, the Flask framework handles the HTTP request and generates a poem. LitBit looks up the selected book's
.json file and prints 3 random lines, along with the book's title and cover image.
Using the Hashids library, the indices of each line are encoded into a single URL, which can uniquely identify this generated poem so that the poem can be shared.