Skip to main content
LitBit website screenshot - Shows the header logo and slogan, as well as a cropped list of available book titles and authors

LitBit

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

LitBit sample poem screenshot. The poem is generated from Alice's Adventures in Wonderland and the image shows the book's title and poster, followed by the generated poem, and a permalink to the poem.

LitBit Poem Screenshot Transcription:

"Every Line:"

"Bore it as well as she could."

"Change the subject."

Book Processing

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.

LitBit second sample poem screenshot. This poem is generated from A Tole of Two Cities and the image shows the book's title and poster, followed by the poem, and a permalink to the poem.

LitBit Poem Screenshot Transcription:

"Human Sympathy."

"Evidently understood it."

"And the letter E."

Poem Creation

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.