Updated displayed text for timelines. Trying to get only new stuff to show up when it's refreshed, but that's not quite working yet.
This commit is contained in:
parent
d7aa704cf1
commit
cabe5058ff
55
ratatoskr.sh
55
ratatoskr.sh
@ -172,11 +172,7 @@ local json="$(jq -n --arg status "$text" \
|
||||
|
||||
# Display timelines
|
||||
show_timeline() {
|
||||
if [[ -n "${since_id}" ]]; then
|
||||
result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/v1/timelines/${timeline:-home}" -d "since_id=${since_id}")"
|
||||
else
|
||||
result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/v1/timelines/${timeline:-home}")"
|
||||
fi
|
||||
result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/v1/timelines/${timeline:-home}")"
|
||||
|
||||
# Error checking
|
||||
# Check if the result is a valid JSON
|
||||
@ -186,6 +182,16 @@ show_timeline() {
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ "${result}" == "${oldResult}" ]]; then
|
||||
return
|
||||
elif [[ ${#oldResult} -gt 5 ]]; then
|
||||
local temperaryVariable="${result}"
|
||||
result="${result//${oldResult%\]}/}"
|
||||
result="${result%,\]}]"
|
||||
oldResult="${temperaryVariable}"
|
||||
play_sound new_${timeline:-home}
|
||||
fi
|
||||
|
||||
error=$(echo "$result" | jq -r '.error // "null"' 2> /dev/null)
|
||||
if [[ "${error:-null}" != "null" ]]; then
|
||||
echo "Error fetching ${timeline:-home} timeline: $error"
|
||||
@ -193,22 +199,31 @@ show_timeline() {
|
||||
return
|
||||
fi
|
||||
|
||||
# process the response to get the latest event id
|
||||
latest_id="$(jq -r '.[].id' <<< "$result")"
|
||||
if [[ "${since_id}" != "${latest_id}" ]]; then
|
||||
# handle new events
|
||||
events="$(jq -r '.[].content' <<< "$result")"
|
||||
stripped_events="$(echo "$events" | sed -E 's/<[^>]+>//g')"
|
||||
stripped_events="${stripped_events//'/\'}"
|
||||
usernames="$(jq -r '.[].account.username' <<< "$result")"
|
||||
echo -e "$usernames" | while read -r username; do
|
||||
# handle new events
|
||||
events="$(jq -r '.[].content' <<< "$result")"
|
||||
spoiler_text="$(jq -r '.[].spoiler_text' <<< "$result")"
|
||||
created_at="$(jq -r '.[].created_at' <<< "$result")"
|
||||
stripped_events="$(echo "$events" | sed -E 's/<[^>]+>//g')"
|
||||
stripped_events="${stripped_events//'/\'}"
|
||||
usernames="$(jq -r '.[].account.username' <<< "$result")"
|
||||
echo -e "$usernames" | while read -r username; do
|
||||
spoiler="$(echo "$spoiler_text" | head -n 1)"
|
||||
created="$(echo "$created_at" | head -n 1)"
|
||||
created="${created%.*}"
|
||||
created="${created/T/ at }"
|
||||
if [ -z "$spoiler" ]; then
|
||||
echo "$username: $(echo "$stripped_events" | head -n 1)"
|
||||
stripped_events="$(echo "$stripped_events" | tail -n +2)"
|
||||
echo
|
||||
done
|
||||
play_sound new_${timeline}
|
||||
since_id="$latest_id"
|
||||
fi
|
||||
echo "Posted $created"
|
||||
else
|
||||
echo "$username [$spoiler]: $(echo "$stripped_events" | head -n 1)"
|
||||
echo "Posted $created"
|
||||
fi
|
||||
stripped_events="$(echo "$stripped_events" | tail -n +2)"
|
||||
spoiler_text="$(echo "$spoiler_text" | tail -n +2)"
|
||||
created_at="$(echo "$created_at" | tail -n +2)"
|
||||
echo
|
||||
done
|
||||
oldResult="${result}"
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user