Skip to content

warmlogic/haikuincidence

Repository files navigation

Haikuincidence

Find tweets that contain coincidental haikus, and tweet these beautiful poems.

You're a poet and
you didn't even know it.
Hey, that's a haiku! ✌️

Setup

App data

  1. Add phrases to data/track.txt to only search for tweets that contain any of the exact strings, one string per line (see the documentation about track for more info)
    1. If file does not exist or is empty, gets tweets from the sample stream
  2. Add phrases to data/ignore_tweet.txt to ignore tweets that contain tokens from any of these strings, one string per line. Uses AND and OR logic like the track list, but tokens for AND (a single line) can match anywhere. Also matches basic plural versions of words (e.g., dog in data/ignore_tweet.txt will match dogs in a tweet's text). See the function text_contains_ignore_list_plural (in utils/text_utils.py) for more info.
    1. Whether or not this file exists, by default this program ignores tweets with words read in the get_ignore_tweet_list function (in utils/data_utils.py)
  3. Add phrases to data/ignore_profile.txt to ignore tweets from accounts whose descriptions contain any of these strings. OR logic only; matches substrings.
  4. Add pre-defined syllable counts to data/syllables.json

Local Python environment

  1. Install poetry as described here
  2. Install requirements: poetry install

Credentials and other variables

If running the app on Heroku (see below), .env is not needed but it may still be convenient to fill in the environment variables.

  1. Copy the (hidden) .env_template.ini file to .env
  2. Edit .env to include your credentials (don't commit this file)

Database

  • If running the app on Heroku, you can easily provision a database for your app by installing the Postgres add-on (see below).
    • Your database credentials will automatically be added to your app's Config Vars.
  • If not running the app on Heroku, you'll need to set up your own database.
    • Add your database credentials to .env

Run the application

Locally

  1. Run the application: poetry run python haikuincidence/app.py
    1. Alternatively, activate the virtual environment that poetry created by running poetry shell and then run the script: python haikuincidence/app.py
    2. Deactivate the virtual environment by running deactivate

As a Heroku app

These instructions use the Heroku CLI

  1. Fork this repo on GitHub and ensure you have a branch called main
  2. Create a new app on Heroku: heroku create my-app-name
  3. Install add-ons for:
    1. Papertrail
      1. heroku addons:create papertrail -a my-app-name
    2. Postgres
      1. heroku addons:create heroku-postgres -a my-app-name
  4. Create a new token: heroku authorizations:create -d "my cool token description"
    1. Add the token to your GitHub repo's Secrets under the name HEROKU_API_KEY
  5. Add your Heroku app's name to the GitHub repo's Secrets under the name HEROKU_APP_NAME
  6. Configure the application by adding environment variables as Config Vars
  7. Commit and push to your GitHub repo's main branch
    1. This can be through committing a change, merging a PR, or just running git commit -m "empty commit" --allow-empty
    2. This will use GitHub Actions to build the app using Docker and deploy to Heroku

Heroku logs

  1. View the logs via the Heroku CLI or on Papertrail

Attribution

I borrowed and adapted code from these nice resources. Thank you!

License

Copyright (c) 2018 Matt Mollison Licensed under the MIT license.

About

Find tweets that contain coincidental haikus

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published