2022-11-12 14:18:00 +01:00
|
|
|
# Death Notifier
|
|
|
|
Get notified when a famous person dies.
|
|
|
|
|
|
|
|
Wikipedia's editors [are known](https://knowyourmeme.com/memes/wikipedia-editors-when-someone-dies) for updating pages
|
2022-11-16 19:44:39 +01:00
|
|
|
as soon as someone has died.
|
2022-11-12 14:18:00 +01:00
|
|
|
Why not turn that into a service?
|
|
|
|
This tool regularly checks if people are still alive according to Wikipedia, and emails you as soon as that changes.
|
|
|
|
|
|
|
|
|
|
|
|
## Development
|
|
|
|
### Requirements
|
2023-08-30 22:35:35 +02:00
|
|
|
* PHP 8.1+ (i.e. `apt install php php-cgi`) (compiled with Argon2 support)
|
2022-11-18 12:37:35 +01:00
|
|
|
* [PHP cURL](https://www.php.net/manual/en/book.curl.php) (i.e. `apt install php-curl`)
|
2022-11-27 11:39:40 +01:00
|
|
|
* [PHP DOM](https://www.php.net/manual/en/book.dom.php) (i.e. `apt install php-dom`)
|
2023-09-04 14:54:45 +02:00
|
|
|
* [PHP mbstring](https://www.php.net/manual/en/book.mbstring.php) (i.e. `apt install php-mbstring`)
|
2022-11-18 12:37:35 +01:00
|
|
|
* [PHP SQLite 3](https://www.php.net/manual/en/book.sqlite3.php) (i.e. `apt install php-sqlite3`)
|
2022-11-27 15:44:23 +01:00
|
|
|
* [composer](https://getcomposer.org/) (make sure `composer.phar` is on your path)
|
2022-11-12 14:18:00 +01:00
|
|
|
* [npm](https://www.npmjs.com/)
|
|
|
|
|
|
|
|
### Setting up
|
2023-03-20 13:55:31 +01:00
|
|
|
Install the dependencies.
|
2023-03-20 12:55:32 +01:00
|
|
|
Run this after cloning the repo, and each time after pulling new commits.
|
|
|
|
```shell
|
|
|
|
composer.phar install
|
|
|
|
npm ci
|
2022-11-12 14:18:00 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
### Building
|
2023-03-20 12:55:32 +01:00
|
|
|
* Build the tool in `dist/` for development
|
|
|
|
```shell
|
|
|
|
npm run dev
|
|
|
|
```
|
|
|
|
* Same as above, but automatically rebuild whenever source code is changed
|
|
|
|
```shell
|
|
|
|
npm run dev:server
|
|
|
|
```
|
|
|
|
* Build the tool in `dist/` for deployment
|
|
|
|
```shell
|
|
|
|
npm run deploy
|
|
|
|
```
|
2022-11-12 14:18:00 +01:00
|
|
|
|
|
|
|
### Pre-commit
|
2023-03-20 12:55:32 +01:00
|
|
|
If you changed the version number or updated any dependencies, update the lock files:
|
|
|
|
```shell
|
|
|
|
composer.phar update
|
|
|
|
npm install
|
2022-11-12 14:18:00 +01:00
|
|
|
```
|
|
|
|
|
2023-08-30 22:31:05 +02:00
|
|
|
### Static analysis and tests
|
|
|
|
Note that PHPUnit suppresses output from `print`.
|
|
|
|
Instead, you can use `fwrite(STDERR, print_r("my message", TRUE));`.
|
|
|
|
|
2023-03-20 12:55:32 +01:00
|
|
|
* Run static analysis
|
|
|
|
```shell
|
|
|
|
npm run analyze
|
|
|
|
```
|
|
|
|
* Run all tests
|
|
|
|
```shell
|
|
|
|
npm run test
|
|
|
|
```
|
2023-08-30 22:31:05 +02:00
|
|
|
* Run only select tests
|
2023-03-20 12:55:32 +01:00
|
|
|
```shell
|
2023-08-30 22:31:05 +02:00
|
|
|
npm run test -- --test-filter="test-name file-name"
|
2023-03-20 12:55:32 +01:00
|
|
|
```
|
2023-08-30 22:31:05 +02:00
|
|
|
Note that a `test-name` of `''` and a `file-name` of `.` matches all tests.
|
|
|
|
|
|
|
|
* Run all tests in package
|
|
|
|
```shell
|
|
|
|
npm run test -- --test-filter="'' com/fwdekker/deathnotifier/wikipedia/"
|
|
|
|
```
|
|
|
|
* Run all tests in class
|
|
|
|
```shell
|
|
|
|
npm run test -- --test-filter="'' com/fwdekker/deathnotifier/wikipedia/WikipediaTest.php"
|
|
|
|
```
|
|
|
|
* Run only specific test
|
|
|
|
```shell
|
|
|
|
npm run test -- --test-filter="test_query_detects_dead_person ."
|
|
|
|
```
|
2023-03-20 12:55:32 +01:00
|
|
|
* Run static analysis and tests
|
|
|
|
```shell
|
|
|
|
npm run check
|
|
|
|
```
|
2022-11-13 15:23:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
## Deployment
|
2023-03-20 12:55:32 +01:00
|
|
|
### Build
|
2022-11-13 15:23:26 +01:00
|
|
|
Build the software and move it to the right directory.
|
2023-03-20 12:55:32 +01:00
|
|
|
```shell
|
|
|
|
npm run deploy
|
|
|
|
mv dist/ /var/www/death-notifier/
|
2022-11-13 15:23:26 +01:00
|
|
|
```
|
|
|
|
|
2023-03-20 12:55:32 +01:00
|
|
|
### Configuration
|
|
|
|
Inside the installation directory, create `config.ini.php` and use it to override values from `config.default.ini.php`.
|
|
|
|
Make sure only the user that runs PHP can read/write `config.ini.php`.
|
|
|
|
|
|
|
|
### Cron jobs
|
2023-09-04 14:54:45 +02:00
|
|
|
You should run the `process-email-queue` and `update-trackings` actions regularly;
|
2023-03-20 12:55:32 +01:00
|
|
|
recommended is every minute and every five minutes, respectively.
|
|
|
|
For example, you can add the following lines to your crontab (e.g. using `sudo -u www crontab -e`):
|
2022-11-13 15:23:26 +01:00
|
|
|
```
|
2022-12-04 16:58:12 +01:00
|
|
|
* * * * * cd /var/www/death-notifier && php /var/www/death-notifier/api.php action=process-email-queue password=secret_password
|
2023-09-04 14:54:45 +02:00
|
|
|
*/5 * * * * cd /var/www/death-notifier && php /var/www/death-notifier/api.php action=update-trackings password=secret_password
|
2022-11-13 15:23:26 +01:00
|
|
|
```
|
2023-03-20 12:55:32 +01:00
|
|
|
Replace `secret_password` with the password you configured in `config.ini.php`.
|
|
|
|
|
|
|
|
### Logs
|
2023-03-20 13:55:31 +01:00
|
|
|
It is recommended to also use a tool such as
|
|
|
|
[`newsyslog`](https://man.freebsd.org/cgi/man.cgi?query=newsyslog.conf&sektion=5) to manage log rotation.
|
2023-03-20 12:55:32 +01:00
|
|
|
For example, create the file `/etc/newsyslog.conf.d/death-notifier.conf` with the following contents:
|
|
|
|
```
|
2023-03-20 13:55:31 +01:00
|
|
|
/var/www/death-notifier/.death-notifier.log www:www 600 7 * @T00 JE
|
|
|
|
/var/www/death-notifier/.death-notifier.db.log www:www 600 7 * $W0D23 JpE
|
2023-03-20 12:55:32 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
### Initialize
|
|
|
|
Open `index.html` in an interactive browser to initialize the database.
|
|
|
|
Make sure only the user that runs PHP can read/write `.death-notifier.db`.
|
|
|
|
|
|
|
|
### Inspection
|
|
|
|
You can use a tool such as [VisiData](https://www.visidata.org/) to manually inspect the database contents on the
|
|
|
|
command line.
|