Created
August 18, 2025 21:50
-
-
Save jooray/f6ae93a34a733ef68bd44ce53b2c1b21 to your computer and use it in GitHub Desktop.
Get number of contributors from btcpayserver campaign, for notifications through scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This is the crowdfunding webpage | |
URL="https://your.btcpayserver.com/apps/yourstoreid/crowdfund" | |
# Fetch the page | |
HTML=$(curl -s "$URL") | |
if [ $? -ne 0 ]; then | |
echo "Error fetching page" >&2 | |
exit 1 | |
fi | |
# Method 1: Extract from the h3 element inside crowdfund-body-total-contributors div | |
# This looks for the pattern where we have the div with the specific id, then captures the h3 content | |
CONTRIBUTORS=$(echo "$HTML" | grep -A2 'id="crowdfund-body-total-contributors"' | grep '<h3' | sed -n 's/.*>\([0-9]*\)<.*/\1/p') | |
# If method 1 didn't work, try method 2 | |
if [ -z "$CONTRIBUTORS" ]; then | |
# Method 2: Extract from JavaScript srvModel variable | |
CONTRIBUTORS=$(echo "$HTML" | grep -o '"totalContributors":[0-9]*' | grep -o '[0-9]*$') | |
fi | |
if [ -z "$CONTRIBUTORS" ]; then | |
echo "Could not find contributor count" >&2 | |
exit 1 | |
fi | |
echo "$CONTRIBUTORS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment