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
|
# Display timelines
|
||||||
show_timeline() {
|
show_timeline() {
|
||||||
if [[ -n "${since_id}" ]]; then
|
result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/v1/timelines/${timeline:-home}")"
|
||||||
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
|
|
||||||
|
|
||||||
# Error checking
|
# Error checking
|
||||||
# Check if the result is a valid JSON
|
# Check if the result is a valid JSON
|
||||||
@ -186,6 +182,16 @@ show_timeline() {
|
|||||||
return
|
return
|
||||||
fi
|
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)
|
error=$(echo "$result" | jq -r '.error // "null"' 2> /dev/null)
|
||||||
if [[ "${error:-null}" != "null" ]]; then
|
if [[ "${error:-null}" != "null" ]]; then
|
||||||
echo "Error fetching ${timeline:-home} timeline: $error"
|
echo "Error fetching ${timeline:-home} timeline: $error"
|
||||||
@ -193,22 +199,31 @@ show_timeline() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# process the response to get the latest event id
|
# handle new events
|
||||||
latest_id="$(jq -r '.[].id' <<< "$result")"
|
events="$(jq -r '.[].content' <<< "$result")"
|
||||||
if [[ "${since_id}" != "${latest_id}" ]]; then
|
spoiler_text="$(jq -r '.[].spoiler_text' <<< "$result")"
|
||||||
# handle new events
|
created_at="$(jq -r '.[].created_at' <<< "$result")"
|
||||||
events="$(jq -r '.[].content' <<< "$result")"
|
stripped_events="$(echo "$events" | sed -E 's/<[^>]+>//g')"
|
||||||
stripped_events="$(echo "$events" | sed -E 's/<[^>]+>//g')"
|
stripped_events="${stripped_events//'/\'}"
|
||||||
stripped_events="${stripped_events//'/\'}"
|
usernames="$(jq -r '.[].account.username' <<< "$result")"
|
||||||
usernames="$(jq -r '.[].account.username' <<< "$result")"
|
echo -e "$usernames" | while read -r username; do
|
||||||
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)"
|
echo "$username: $(echo "$stripped_events" | head -n 1)"
|
||||||
stripped_events="$(echo "$stripped_events" | tail -n +2)"
|
echo "Posted $created"
|
||||||
echo
|
else
|
||||||
done
|
echo "$username [$spoiler]: $(echo "$stripped_events" | head -n 1)"
|
||||||
play_sound new_${timeline}
|
echo "Posted $created"
|
||||||
since_id="$latest_id"
|
fi
|
||||||
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