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
- set the env values (see below)
- set a time to run e.g. every 30 mins
- set the command listed below under "Cron job command"
- Test cronjob works
- Relax
How it works
We run this on the newcardigan wordpress server.
- With a cron job we call the civiCRM API use
cv
to grab the details of the latest cardiParty - We pipe that string into a python script
- 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
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
)
Cron job command
cv api4 Event.get '{"select":["title","address.city","start_date","summary"],"join":[["Address AS address","LEFT",["loc_block_id.address_id","=","address.id"]]],"orderBy":{"start_date":"DESC"},"limit":1}' | ./webhook.py
This should pipe a string like this into the script:
[{"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=cardipartyfeed
.
This special cardipartyfeed
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.