getopts + visibility
This commit is contained in:
parent
6dbe872cd7
commit
24d9c1985d
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
### get-last-rss-post.sh
|
||||
### Usage: ./get-last-rss-post.sh [-t] URL
|
||||
### $0
|
||||
### Usage: ./$0 [-t] URL
|
||||
###
|
||||
### Downloads the RSS feed of the URL and checks the latest post.
|
||||
### It provides a simple way to copy/paste the Title and Link of the post.
|
||||
|
@ -9,23 +9,58 @@
|
|||
### If not, it exits.
|
||||
|
||||
help() {
|
||||
sed -rn 's/^### ?//;T;p' "$0"
|
||||
echo "Usage: $0 [-d] [-t VISIBILITY] [-h] URL"
|
||||
echo ""
|
||||
echo " Downloads the RSS feed of the URL and checks the latest post."
|
||||
echo " It provides a simple way to copy/paste the Title and Link of the post."
|
||||
echo " If toot is installed, it can post the status with custom visibility."
|
||||
echo " Arguments:"
|
||||
echo " -d Checks if the Publication Date of the post is Today."
|
||||
echo " If not, it exits."
|
||||
echo " -t Post the link with toot. A prompt will ask confirmation."
|
||||
echo " Accepted value: direct, unlisted, public, private"
|
||||
echo " -h Displays this message."
|
||||
echo ""
|
||||
}
|
||||
|
||||
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]] || [[ "$1" == "" ]]; then
|
||||
while getopts ":dt:h" opt; do
|
||||
case $opt in
|
||||
d)
|
||||
TODAY=$(date +'%d %b %Y')
|
||||
CHECK_TODAY=1
|
||||
;;
|
||||
t)
|
||||
TOOT=1
|
||||
case "${OPTARG}" in
|
||||
direct|unlisted|public|private)
|
||||
VISIBILITY=${OPTARG}
|
||||
;;
|
||||
*)
|
||||
echo "Invalid visibility option: --$OPTARG"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
h)
|
||||
# Help
|
||||
help
|
||||
exit 1
|
||||
;;
|
||||
\?)
|
||||
echo "Invalid option: -$OPTARG" >&2
|
||||
;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
if [[ "$*" == "" ]]; then
|
||||
help
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ "$1" == "-t" ]] || [[ "$1" == "--today" ]]; then
|
||||
TODAY=$(date +'%d %b %Y')
|
||||
echo "Checking if the post pubblication days is ${TODAY}…"
|
||||
set -- "$2" # Reset arguments - link becomes $1
|
||||
CHECK_TODAY=1
|
||||
fi
|
||||
|
||||
today() {
|
||||
# Checks if pubDate is $TODAY
|
||||
echo "Checking if the post pubblication days is ${TODAY}…"
|
||||
echo $PUB_DATE | grep -q "$TODAY"
|
||||
if [[ "$?" == "0" ]]; then # pubDate is $TODAY
|
||||
echo "Published Date is today - good!"
|
||||
|
@ -39,8 +74,9 @@ yes_or_no() {
|
|||
while true; do
|
||||
read -p "$* [y/n]: " yn
|
||||
case $yn in
|
||||
[Yy]*) echo "Latest article from my blog: \"$TITLE\"\n\n$LINK" | /opt/homebrew/bin/toot post; return 0 ;;
|
||||
[Nn]*) echo "Exiting." ; exit 0 ;;
|
||||
[Yy]*) echo "Latest article from my blog: \"$TITLE\"\n\n$LINK" | \
|
||||
/opt/homebrew/bin/toot post -v $VISIBILITY ; return 0 ;;
|
||||
[Nn]*) echo "Exiting." ; cleanup 0 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
@ -52,7 +88,7 @@ cleanup () {
|
|||
}
|
||||
|
||||
echo "Downloading latest XML feed…"
|
||||
wget -q -O feed.xml $1
|
||||
wget -q -O feed.xml $*
|
||||
if ! [[ $? == "0" ]]; then echo "Error."; cleanup 1; else echo "Done."; fi
|
||||
|
||||
# Check if downloaded file has <rss> tag
|
||||
|
@ -78,6 +114,6 @@ echo "\nCopy and Paste this:\n\n+++++"
|
|||
echo "Latest article from my blog: \"$TITLE\"\n\n$LINK"
|
||||
echo "+++++"
|
||||
|
||||
yes_or_no "Post the it as status?"
|
||||
if [[ "$TOOT" == "1" ]]; then yes_or_no "Post it on Mastodon?"; fi
|
||||
|
||||
cleanup 0
|
BIN
screenshot.jpg
BIN
screenshot.jpg
Binary file not shown.
Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 20 KiB |
Loading…
Reference in New Issue