twtxt-c/twtxt-c

119 lines
3.6 KiB
Plaintext
Raw Permalink Normal View History

2021-07-08 15:59:13 +00:00
#!/bin/bash
2021-07-03 09:07:14 +00:00
PROGNAME=${0##*/}
VERSION="0.0.1"
error_exit() {
printf "%s: %s\n" "$PROGNAME" "${1:-"Unknown Error"}" >&2
exit 1
}
usage() {
printf "usage: %s [OPTIONS] COMMAND [ARGS]\n" "$PROGNAME"
printf "Simple client for twtxt\n"
printf "Options:\n
-c, --config PATH Specify a custom config file location.
-v, --verbose Enable verbose output for debugging purposes.
--version Show the version and exit.
-h, --help Show this message and exit.
2021-07-03 09:07:14 +00:00
Commands:
init Setting up twtxt.
2021-07-03 09:07:14 +00:00
config Get or set config item.
follow Add a new source to your followings.
following Return the list of sources youre following.
timeline Retrieve your personal timeline.
tweet Append a new tweet to your twtxt file.
unfollow Remove an existing source from your...
view Show feed of given source.
reg list Show registers
reg add Add your twtxt to registry
reg users List users on the registry
2021-07-08 14:59:52 +00:00
reg twts Fetch recent tweets from registry
reg mentions search for mentions by url
reg tag Search for tags
"
2021-07-03 09:07:14 +00:00
}
2021-07-08 14:59:52 +00:00
read_config () {
declare -A v=()
while read -r var value; do
v[$var]=$value
done < $config/registry
}
2021-07-03 09:07:14 +00:00
case $1 in
-h | --help)
usage; exit ;;
-* | --*)
usage; error_exit "unknown option $1" ;;
init)
2021-07-04 02:31:07 +00:00
read -p "Your desired nickname [$USER]: " nick
nick=${nick:-"$USER"}
read -p "Type path to your twtxt [/home/$USER/twtxt.txt]: " path_to_twtxt
2021-07-04 02:31:07 +00:00
path_to_twtxt=${path_to_twtxt:-"/home/$USER/twtxt.txt"}
echo "" >> $path_to_twtxt
read -p "Type path to your twtxt config folder [/home/$USER/.config/twtxt-c/]: " config
config=${config:-"/home/$USER/.config/twtxt-c/"}
mkdir -p $config
read -p "URL to twtxt [https://example.com/twtxt.txt]: " url
url=${url:-"https://example.com/twtxt.txt"}
2021-07-04 02:39:01 +00:00
printf "[twtxt]\n nick = %s\n twtfile = %s\n url = %s\n" "$nick" "$path_to_twtxt" "$url" >> $config/config
2021-07-08 14:59:52 +00:00
printf "https://twtxt.envs.net/api/plain/\nhttps://twtxt.tilde.institute/api/plain/\n" > $config/registry
;;
2021-07-03 14:26:18 +00:00
tweet)
2021-07-04 02:55:16 +00:00
export config=/home/$USER/.config/twtxt-c/config
2021-07-03 14:26:18 +00:00
printf "%s\t%s\n" "$(date +'%FT%T%:z')" "$2" >> $(awk '/twtfile/ {print $3}' $config)
;;
2021-07-05 15:04:02 +00:00
view)
curl $2 2>/dev/null | grep -v "#" | awk 'BEGIN { FS = "\t" } ; {print $2}'
;;
reg)
case $2 in
2021-07-08 14:59:52 +00:00
list)
cat /home/$USER/.config/twtxt-c/registry
;;
add)
2021-07-08 14:59:52 +00:00
config=/home/$USER/.config/twtxt-c/
declare -A v=()
while read -r line; do
var=$(echo $line | awk '{print $1}' )
value=$(echo $line | awk '{print $3}' )
v[$var]=$value
done < $config/config
req="https://twtxt.tilde.institute/api/plain/users?url=${v[url]}&nickname=${v[nick]}"
req2="https://twtxt.envs.net/api/plain/users?url=${v[url]}&nickname=${v[nick]}"
echo "post these requests:"
echo "curl -X POST $req"
echo "curl -X POST $req2"
#curl -X POST $req
#curl -X POST $req2
# I have commented the actual curl request so that I accidentally re-register myself during testing
;;
users)
curl 'https://twtxt.tilde.institute/api/plain/users'
curl 'https://twtxt.envs.net/api/plain/users' ;;
twts)
curl 'https://twtxt.tilde.institute/api/plain/tweets'
curl 'https://twtxt.envs.net/api/plain/tweets'
;;
mentions)
url=$3
req="https://twtxt.tilde.institute/api/plain/mentions?url=$url"
req2="https://twtxt.envs.net/api/plain/mentions?url=$url"
curl $req
curl $req2
;;
tag)
tag=$3
req="https://twtxt.tilde.institute/api/plain/tags/$tag"
req2="https://twtxt.envs.net/api/plain/tags/$tag"
curl $req
curl $req2
;;
esac ;;
*)
printf "Work in progress\n" ;;
2021-07-03 09:07:14 +00:00
esac