Coronavirus disease 2019 (COVID-19) information on Telegram Messenger @corona_cases_bot
Raison d´être
The Internet interprets censorship as damage and routes around it.
- John Gilmore
Setup environment
Install
- Clojure
- Babashka
- coronavirus-tracker-api
- postgresql:
sudo apt install postgresql postgresql-contrib
sudo systemctl status postgresql.service
sudo systemctl stop postgresql.service
# set --export PATH /usr/lib/postgresql/*/bin $PATH
initdb pg
sudo chown --recursive postgres:postgres pg/
sudo chmod --recursive u=rwx,g=---,o=--- pg/
sudo -su postgres
fish # start he fish-shell for the postgres user
set --export PATH /usr/lib/postgresql/*/bin $PATH
postgres -D pg & # this doesn't work: pg_ctl -D pg -l logfile start
Open new console and log in
psql --dbname=postgres
\conninfo
-- list databases:
\l
\l+
SELECT datname FROM pg_database;
Create
- Telegram Chatbot
- Heroku App, optionally add the Papertrail add-on
Configure
- Local environment variables. Create
.env
file in your project root directory:
$ touch .env
containing:
# Value must be lower-cased, without the "" chars
CORONA_ENV_TYPE=devel
#
# https://clojure.org/guides/getting_started#_installation_on_linux
# See also `.heroku-local.env` and the output of `clojure --help | grep Version`
CLOJURE_CLI_VERSION=1.10.1.763
#
# HEROKU tokens for:
PAPERTRAIL_API_TOKEN=<...>
TELEGRAM_TOKEN="<...>"
- Heroku Config Vars. See https://dashboard.heroku.com/apps/<YOUR-HEROKU-APP-NAME>/settings. See also:
$ heroku config --app <YOUR-HEROKU-APP-NAME>
CLOJURE_CLI_VERSION: 1.10.1.763
COMMIT: ...
CORONA_ENV_TYPE: HOKUSPOKUS
PAPERTRAIL_API_TOKEN: ...
REPL_PASSWORD: ...
REPL_USER: ...
TELEGRAM_TOKEN: ...
Develop
- Start the coronavirus-tracker-api:
$ pipenv run start
- In Emacs Cider
M-x cider-jack-in-clj
, or start the nREPL from the command line:
$ clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.8.3"} refactor-nrepl/refactor-nrepl {:mvn/version "2.5.0"} cider/cider-nrepl {:mvn/version "0.25.5"}}}' -m nrepl.cmdline --middleware '["refactor-nrepl.middleware/wrap-refactor", "cider.nrepl/cider-middleware"]'
and connect to it from the editor of your choice.
- Start the telegram chatbot long-polling:
user> (require '[corona.telegram])
user> (corona.telegram/start)
- Start the web server:
user> (require '[corona.web])
user> (alter-var-root #'system component/start)
and check the http://localhost:5050/ if it's running.
Run locally
$ bin/build; and heroku local --env=.heroku-local.env
# or:
# bin/build; and heroku local --env=.heroku-local.env --set COMMIT=...
Deploy to Heroku
$ bb heroku.clj deploy --heroku-env <YOUR-HEROKU-APP-NAME>
MySQL -> PostgreSQL script conversion
psql --dbname=postgres -a -f dbase/postgres.sql
psql --dbname=postgres -q -a -f dbase/postgres.sql | rg "ERROR\|NOTICE|WARN"
# psql --dbname=postgres -q -a -f dbase/drop-everything.sql
psql --dbname=postgres
\dt -- list tables
\ds -- list sequences
\di -- list indices
Others
heroku pt ":type -'ssl-client-cert' -'$MY_TELEGRAM_ID'" --app <YOUR-HEROKU-APP-NAME> | grep -v -e '^[[:space:]]*$