Created
June 3, 2022 04:44
-
-
Save keb/3d83b176cb8aaa6b0c00cdc482bbe2b5 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env bash | |
# When using Curl in shell scripts, always pass -fsSL, which: | |
# Treats non-2xx/3xx responses as errors (-f). | |
# Disables the progress meter (-sS). | |
# Handles HTTP redirects (-L). | |
# curl -fsSL -X GET "https://mas.to/users/keb.rss" | grep -oPm1 "(?<=<lastBuildDate>)[^<]+" | |
FILE=last_date.txt | |
ISSUE_URL=https://api.github.com/repos/keb/keb.github.io/issues/1/comments | |
AUTH_TOKEN=$GITHUB_AUTH_TOKEN | |
FEED=$(curl -fsSL -X GET https://mas.to/users/keb.rss) | |
LAST_DATE_STR=$(echo "$FEED" | grep -oPm1 "(?<=<lastBuildDate>)[^<]+") | |
LAST_DATE=$(date -d "$LAST_DATE_STR" +%s) | |
if [ -f "$FILE" ]; then | |
OLD_DATE_STR=$(head -n 1 "$FILE") | |
OLD_DATE=$(date -d "$OLD_DATE_STR" +%s) | |
if [ $LAST_DATE -gt $OLD_DATE ]; then | |
echo "$LAST_DATE_STR" > "$FILE" | |
# comment on github issue | |
curl \ | |
-X POST \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
-H "Authorization: token $AUTH_TOKEN" \ | |
$ISSUE_URL \ | |
-d '{"body":"dog"}' | |
fi | |
else | |
echo "$LAST_DATE_STR" > "$FILE" | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment