aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorziggys <ziggys@autistici.org>2019-11-11 15:15:32 -0300
committerziggys <ziggys@autistici.org>2019-11-11 15:15:32 -0300
commita6c762571368e5ab2c65363ee380f08866dcb526 (patch)
treed82c3c5a9056318d7ce74c93c1d54e99a53980b1
parent023fdedd44631dc4f3b59fc7db6d75b9d1b1e757 (diff)
parent033ecd591a6de8c46ea453031fdf0c03881dc325 (diff)
downloadgsocial-cli-a6c762571368e5ab2c65363ee380f08866dcb526.tar
gsocial-cli-a6c762571368e5ab2c65363ee380f08866dcb526.zip
Merge branch 'dev'
-rwxr-xr-xgsocial-cli.sh112
1 files changed, 31 insertions, 81 deletions
diff --git a/gsocial-cli.sh b/gsocial-cli.sh
index bad2ae3..b99c632 100755
--- a/gsocial-cli.sh
+++ b/gsocial-cli.sh
@@ -202,16 +202,16 @@ acc_conf () {
# obtain user info
user_info () {
UINFOF="$(mktemp -p "${TMPDIR}")"
- iget_api="${INODE}/api/users/show.xml?screen_name=${IUSER}"
+ iget_api="${INODE}/api/users/show.json?screen_name=${IUSER}"
curl -s "${iget_api}" > "${UINFOF}"
- USERID="$(sed '/^ <id>/ !d; s/ *<[^>]*> *//g' "${UINFOF}")"
- DESCRIPTION="$(sed '/^ <description>/ !d; s/ *<[^>]*> *//g' "${UINFOF}")"
- STATUSESQ="$(sed '/^ <statuses_count>/ !d; s/ *<[^>]*> *//g' "${UINFOF}")"
- FOLLOWSQ="$(sed '/^ <friends_count>/ !d; s/ *<[^>]*> *//g' "${UINFOF}")"
- FOLLOWERSQ="$(sed '/^ <followers_count>/ !d; s/ *<[^>]*> *//g' "${UINFOF}")"
- GROUPSQ="$(sed '/^ <groups_count>/ !d; s/ *<[^>]*> *//g' "${UINFOF}")"
+ USERID="$(jq -r '.id' "${UINFOF}")"
+ DESCRIPTION="$(jq -r '.description' "${UINFOF}")"
+ STATUSESQ="$(jq -r '.statuses_count' "${UINFOF}")"
+ FOLLOWSQ="$(jq -r '.friends_count' "${UINFOF}")"
+ FOLLOWERSQ="$(jq -r '.followers_count' "${UINFOF}")"
+ GROUPSQ="$(jq -r '.groups_count' "${UINFOF}")"
printf "\\e%s%s@%s [%s]\\n" "${warn_c}" "${IUSER}" "${NONODE}" "${USERID}"
printf "\\e%s%s\\e[0m\\n" "${info_c}" "${DESCRIPTION}"
@@ -224,7 +224,7 @@ user_info () {
# verify credentials
verify_credentials () {
ACCVERIFY="$(curl -s -u "${USER}:${PASSWORD}" \
- "${NODE}/api/account/verify_credentials.xml" | sed '/^ <error>/ !d')"
+ "${NODE}/api/account/verify_credentials.json" | sed '/^ <error>/ !d')"
test ! -z "${ACCVERIFY}" \
&& printf "\\e%sfatal: \\e%s%s authentication failed %s\\e[0m\\n\\n" \
@@ -243,38 +243,28 @@ tget () {
"${good_c}" "${RETR}" "${good_c}" "${TGET}"
TIMELINEF="$(mktemp -p "${TMPDIR}")"
- OUTPUT0="$(mktemp -p "${TMPDIR}")"
- OUTPUT1="$(mktemp -p "${TMPDIR}")"
- OUTPUT2="$(mktemp -p "${TMPDIR}")"
- OUTPUT3="$(mktemp -p "${TMPDIR}")"
OUTPUT4="$(mktemp -p "${TMPDIR}")"
- SIDSF="$(mktemp -p "${TMPDIR}")"
- SNAMESF="$(mktemp -p "${TMPDIR}")"
- UNAMESF="$(mktemp -p "${TMPDIR}")"
- TEXTSF="$(mktemp -p "${TMPDIR}")"
- SOURCESF="$(mktemp -p "${TMPDIR}")"
- CREATEDSF="$(mktemp -p "${TMPDIR}")"
OIFS="$IFS"
IFS="$(printf '\n')"
case "${TGET}" in
"timeline")
data_api="-d count=${RETR}"
- get_api="${NODE}/api/statuses/home_timeline.xml"
+ get_api="${NODE}/api/statuses/home_timeline.json"
;;
"public")
data_api="-d count=${RETR}"
- get_api="${NODE}/api/statuses/public_timeline.xml"
+ get_api="${NODE}/api/statuses/public_timeline.json"
;;
"mentions")
data_api="-d count=${RETR}"
- get_api="${NODE}/api/statuses/mentions_timeline.xml"
+ get_api="${NODE}/api/statuses/mentions_timeline.json"
;;
"sent")
- get_api="${NODE}/api/statuses/user_timeline.xml"
+ get_api="${NODE}/api/statuses/user_timeline.json"
;;
"tag")
- get_uri="${GETATAG}.xml&count=${RETR:=20}"
+ get_uri="${GETATAG}.json&count=${RETR:=20}"
get_api="${NODE}/api/statusnet/tags/timeline/${get_uri}"
TGET="${TGET} #${GETATAG}"
warn_c="[0;36m"
@@ -284,7 +274,7 @@ tget () {
RNODE="https://${RUSER##*@}"
GETUSER="${RUSER%%@*}"
get_uri="include_rst=true&screen_name=${GETUSER}&count=${RETR:=20}"
- get_api="${RNODE}/api/statuses/user_timeline.xml?${get_uri}"
+ get_api="${RNODE}/api/statuses/user_timeline.json?${get_uri}"
TGET="${TGET} ${RUSER}"
IUSER="${GETUSER}"
INODE="${RNODE}"
@@ -299,13 +289,7 @@ tget () {
curl -s -u "$USER:$PASSWORD" "${data_api}" "${get_api}" \
> "${TIMELINEF}"
- SID="$(sed '/^[ \t] <id>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
- SNAME="$(sed '/^[ \t] .<screen_name>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
-
- UNAME="$(sed '/^[ \t] .<name>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
- TEXT="$(sed '/^[ \t] <text>/ !d; s/ *<[^>]*> *//g; s/%/%%/g' "${TIMELINEF}")"
- SSOURCE="$(sed '/^[ \t].<source>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
- CREATED="$(sed '/^[ \t].<created_at>/ !d; s/ *<[^>]*> *//g' "${TIMELINEF}")"
+ SID="$(jq -r '.[] | .id' "${TIMELINEF}")"
test -z "${SID}" \
&& printf "\\e%swarning:\\e%s command returned an empty output\\e[0m\\n" \
@@ -313,74 +297,40 @@ tget () {
&& printf "exiting now..." \
&& exit 0
- # many shells do not handle arrays, let's make lists
- echo "${SID}" > "${SIDSF}"
- echo "${SNAME}" > "${SNAMESF}"
- echo "${UNAME}" > "${UNAMESF}"
- echo "${TEXT}" > "${TEXTSF}"
- echo "${SSOURCE}" > "${SOURCESF}"
- echo "${CREATED}" > "${CREATEDSF}"
- sed -i 's/&quot;/"/g' "${TEXTSF}"
-
- # let's use awk to concatenate lists
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${SIDSF}" "${SNAMESF}" > "${OUTPUT0}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT0}" "${UNAMESF}" > "${OUTPUT1}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT1}" "${TEXTSF}" > "${OUTPUT2}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT2}" "${SOURCESF}" > "${OUTPUT3}"
- awk '
- BEGIN{IFS="\n"; OFS=":;:"}
- FNR==NR { a[(FNR"")] = $0; next}
- {print a[(FNR"")],$0}' \
- "${OUTPUT3}" "${CREATEDSF}" > "${OUTPUT4}"
-
- # print concatenated file
+ jq -r '.[] | .user.name + ":;:" + .user.screen_name + ":;:" + (.id|tostring) + ":;:" + (.text|split("\n\n")|join(" ")) + ":;:" + (.created_at|tostring) + ":;:" + .source' "${TIMELINEF}" > "${OUTPUT4}"
+
awk -v user="${USER}" '
BEGIN{FS=":;:"; OFS="\n"}
{
if ($2==user)
printf \
- "\033['"$myself_c"'" $3 \
+ "\033['"$myself_c"'" $1 \
"\033['"$uname_c"'" " @" $2 \
- "\033['"$myself_c"'" " [" NR " - id " $1 "]" OFS \
+ "\033['"$myself_c"'" " [" NR " - id " $3 "]" OFS \
"\033[1;30m" $4 OFS \
"\033[1;30m" " - " \
- "\033['"$text_c"'" $6 \
+ "\033['"$text_c"'" $5 \
"\033[1;30m" " from " \
- "\033['"$text_c"'" $5 OFS \
+ "\033['"$text_c"'" $6 OFS OFS \
"\033[0m"
else
printf \
- "\033['"$sname_c"'" $3 \
+ "\033['"$sname_c"'" $1 \
"\033['"$uname_c"'" " @" $2 \
- "\033['"$sid_c"'" " [" NR " - id " $1 "]" OFS \
+ "\033['"$sid_c"'" " [" NR " - id " $3 "]" OFS \
"\033['"$text_c"'" $4 OFS \
"\033['"$text_c"'" " - " \
- "\033['"$meta_c"'" $6 \
+ "\033['"$meta_c"'" $5 \
"\033['"$text_c"'" " from " \
- "\033['"$meta_c"'" $5 OFS \
+ "\033['"$meta_c"'" $6 OFS OFS \
"\033[0m" }' \
"${OUTPUT4}" | more
-
+
history_keep
cat "$OUTPUT4" >> "${HISTORY}" && chmod 600 "${HISTORY}"
IFS="${OIFS}"
+
}
# repeat, favorite, destroy
@@ -431,7 +381,7 @@ rfd () {
verify_credentials
curl -s -u "$USER:$PASSWORD" -d id="${TID}" -d source="${SCRIPTNAME}" \
- "${NODE}/api/${action_api}.xml" > "${CURLOUT}" 2 > "${DN}"
+ "${NODE}/api/${action_api}.json" > "${CURLOUT}" 2 > "${DN}"
CURLOUT_E="$(sed '/error/ !d' "${CURLOUT}")"
test ! -z "${CURLOUT_E}" \
@@ -475,7 +425,7 @@ post () {
/* Leave firs line 'blank' to cancel post\\n \
/* or simply write 'kill!' at any line beginning" \
"${EDITOR:=${d_editor}}" > "${POSTF}"
- post_api="${NODE}/api/statuses/update.xml"
+ post_api="${NODE}/api/statuses/update.json"
;;
"reply")
printf "\\n/to @%s\\n \
@@ -487,7 +437,7 @@ post () {
/* or simply write 'kill!' at any line beginning" \
"${TUSER}" "${TUSER}" "${EDITOR:=${d_editor}}" > "${POSTF}"
data_api="-d in_reply_to_status_id=${TID}"
- post_api="${NODE}/api/statuses/update.xml"
+ post_api="${NODE}/api/statuses/update.json"
;;
"quote")
printf "\\n[QT] @%s (%s): %s\\n \
@@ -498,7 +448,7 @@ post () {
/* Leave first line 'blank' to cancel post\\n \
/* or simply write 'kill!' at any line beginning" \
"${TUSER}" "${TNAME}" "${TSTS}" "${EDITOR:=${d_editor}}" > "${POSTF}"
- post_api="${NODE}/api/statuses/update.xml"
+ post_api="${NODE}/api/statuses/update.json"
esac
sed -i 's/^ *//g' "${POSTF}"