|
||
---|---|---|
src | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
Gruntfile.js | ||
LICENSE | ||
README.md | ||
composer.json | ||
composer.lock | ||
package-lock.json | ||
package.json | ||
phpstan.neon | ||
tsconfig.json |
README.md
Death Notifier
Get notified when a famous person dies.
Wikipedia's editors are known for updating pages as soon as someone has died. 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
- PHP 8.1+ (i.e.
apt install php php-cgi
) (compiled with Argon2 support)- PHP cURL (i.e.
apt install php-curl
) - PHP DOM (i.e.
apt install php-dom
) - PHP mbstring (i.e.
apt install php-mbstring
) - PHP SQLite 3 (i.e.
apt install php-sqlite3
)
- PHP cURL (i.e.
- composer (make sure
composer.phar
is on your path) - npm
Setting up
Install the dependencies. Run this after cloning the repo, and each time after pulling new commits.
composer.phar install
npm ci
Building
- Build the tool in
dist/
for developmentnpm run dev
- Same as above, but automatically rebuild whenever source code is changed
npm run dev:server
- Build the tool in
dist/
for deploymentnpm run deploy
Pre-commit
If you changed the version number or updated any dependencies, update the lock files:
composer.phar update
npm install
Static analysis and tests
Note that PHPUnit suppresses output from print
.
Instead, you can use fwrite(STDERR, print_r("my message", TRUE));
.
-
Run static analysis
npm run analyze
-
Run all tests
npm run test
-
Run only select tests
npm run test -- --test-filter="test-name file-name"
Note that a
test-name
of''
and afile-name
of.
matches all tests.- Run all tests in package
npm run test -- --test-filter="'' com/fwdekker/deathnotifier/wikipedia/"
- Run all tests in class
npm run test -- --test-filter="'' com/fwdekker/deathnotifier/wikipedia/WikipediaTest.php"
- Run only specific test
npm run test -- --test-filter="test_query_detects_dead_person ."
- Run all tests in package
-
Run static analysis and tests
npm run check
Deployment
Build
Build the software and move it to the right directory.
npm run deploy
mv dist/ /var/www/death-notifier/
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
You should run the process-email-queue
and update-trackings
actions regularly;
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
):
* * * * * cd /var/www/death-notifier && php /var/www/death-notifier/api.php action=process-email-queue password=secret_password
*/5 * * * * cd /var/www/death-notifier && php /var/www/death-notifier/api.php action=update-trackings password=secret_password
Replace secret_password
with the password you configured in config.ini.php
.
Logs
It is recommended to also use a tool such as
newsyslog
to manage log rotation.
For example, create the file /etc/newsyslog.conf.d/death-notifier.conf
with the following contents:
/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
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 to manually inspect the database contents on the command line.