This commit is contained in:
Hugh Rundle 2024-09-16 09:08:29 +10:00
parent ed6f7d7ca8
commit 317b72f178
Signed by: hugh
GPG key ID: A7E35779918253F9
4 changed files with 8 additions and 8 deletions

View file

@ -51,6 +51,6 @@ There are also a couple of other things we need to do:
## RSS feed ## RSS feed
The rss feed is `https://newcardigan.org/category/cardiparties/?feed=cardipartyfeed`. The rss feed is `https://newcardigan.org/category/cardiparties/?feed=featured_image_feed`.
This special `cardipartyfeed` is a slightly modified RSS2 feed. The only thing it does differently is filter out everything that isn't a cardiparty ,and 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. 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.

View file

@ -4,7 +4,7 @@
export PATH=/home/cardigan/rss-discord-bot/venv/bin:usr/local/bin:usr/bin: export PATH=/home/cardigan/rss-discord-bot/venv/bin:usr/local/bin:usr/bin:
source /home/cardigan/rss-discord-bot/venv/bin/activate source /home/cardigan/rss-discord-bot/venv/bin/activate
export CIVICRM_SETTINGS="/var/www/html/wp-content/uploads/civicrm/civicrm.settings.php" export CIVICRM_SETTINGS="/var/www/html/wp-content/uploads/civicrm/civicrm.settings.php"
export DISCORD_SERVER="<server_id>" export DISCORD_GUILD="<server_id>"
export DISCORD_TOKEN="<token>" export DISCORD_TOKEN="<token>"
export DISCORD_CARDIPARTY_PING="<group_id>" export DISCORD_CARDIPARTY_PING="<group_id>"

0
latest_post.txt Normal file
View file

View file

@ -8,12 +8,12 @@ import sys
import feedparser import feedparser
import requests import requests
dc_server = os.getenv("DISCORD_SERVER") # this is actually the instance, not a channel guild = os.getenv("DISCORD_GUILD") # the Discord server/guild id
token = os.getenv("DISCORD_TOKEN") # token for this bot token = os.getenv("DISCORD_TOKEN") # token for this bot
cardiparty_ping = os.getenv("DISCORD_CARDIPARTY_PING") cardiparty_ping = os.getenv("DISCORD_CARDIPARTY_PING")
# get the latest cardiparty with image as enclosure # get the latest cardiparty with image as enclosure
f = feedparser.parse("https://newcardigan.org/category/cardiparties/?feed=cardipartyfeed") f = feedparser.parse("https://newcardigan.org/category/cardiparties/?feed=featured_image_feed")
first = f.entries[0] first = f.entries[0]
# check whether we have already seen this entry # check whether we have already seen this entry
with open("latest_post.txt", "r+") as f: with open("latest_post.txt", "r+") as f:
@ -48,7 +48,7 @@ if guid != first.guid:
}] }]
headers = {'user-agent': 'cardiParty-discord-bot/1.0.0'} headers = {'user-agent': 'cardiParty-discord-bot/1.0.0'}
url = f"https://discord.com/api/webhooks/{dc_server}/{token}" url = f"https://discord.com/api/webhooks/{guild}/{token}"
payload = { payload = {
"thread_name": f"{first.title} | {title}", "thread_name": f"{first.title} | {title}",
"content": content, "content": content,
@ -57,5 +57,5 @@ if guid != first.guid:
} }
r = requests.post(url, json=payload, headers=headers) r = requests.post(url, json=payload, headers=headers)
print(r) print(datetime.now().isoformat(' '), r)
r.raise_for_status() # if we got a 4xx response this will log it r.raise_for_status() # if we got a 4xx response