get_party.sh | ||
latest_post.txt | ||
LICENSE | ||
README.md | ||
requirements.txt | ||
webhook.py |
Discord cardiParty webhook
This is a simple webhook to push new cardiParties into the cardiParty channel.
install
- Create and activate virtual env
- Install requirements:
pip install -r requirements.txt
- Set up a cronjob (see below)
- Test cronjob works
- Relax
How it works
We run this on the newcardigan wordpress server.
- With a cron job we call
get_party.sh
- The shell script set env values and uses the civiCRM API using
cv
to grab the details of the latest cardiParty - We pipe that string into
webhook.py
- The script checks a custom RSS feed for new parties
- If no new party, end
- If new party,
- save the guid to
latest_post.txt
for the next round of checking - use the image and title from the RSS feed and the details from the cv API call
- publish via a webhook to Discord
- save the guid to
env values
These are all set in get_party.sh
, not in crontab. Because we need most of them in a subsequent call (either inside cv
or in webhook.py
) we export
them all.
We need to include some secrets via environment values:
- channel is the channel ID (
DISCORD_CHANNEL
) - token is the secret token for the webhook (
DISCORD_TOKEN
) - cardiparty_ping is the ID of the
@cardiParty ping
role (DISCORD_CARDIPARTY_PING
)
There are also a couple of other things we need to do:
- civicrm_settings - set
CIVICRM_SETTINGS
so thatcv
can find it - venv - we need to activate the venv using
source <path/to/venv>
Cron job command
*/15 * * * * cd /home/cardigan/rss-discord-bot && ./get_party.sh
get_party.sh
should pipe a string like this into webhook.py
:
[{"id":108,"title":"Melbourne Art Library","address.city":"Melbourne","start_date":"2024-04-06 16:30:00","summary":"Melbourne Art Library (MAL) is a not-for-profit lending library that collects specialised art and design texts. They are proudly independent and are curious about what being a 'library' means."}]
RSS feed
The rss feed is https://newcardigan.org/category/cardiparties/?feed=featured_image_feed
.
This special featured_image_feed
is a slightly modified RSS2 feed. The only thing it does differently is include the featured image in an enclosure
so that we can pick it up directly from the feed. See the newcardigan WordPress theme for how this works.