Got a start on the main loop, but jq is being vicious currently, so going to come back to it later.
This commit is contained in:
		
							
								
								
									
										41
									
								
								ratatoskr.sh
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								ratatoskr.sh
									
									
									
									
									
								
							@@ -219,4 +219,45 @@ while getopts "${args}" i ; do
 | 
				
			|||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Main loop
 | 
				
			||||||
 | 
					while : ; do
 | 
				
			||||||
 | 
					   if [[ -n "${since_id}" ]]; then
 | 
				
			||||||
 | 
					        result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/va/timelines/${timeline:-home}?since_id=${since_id}")"
 | 
				
			||||||
 | 
					    else
 | 
				
			||||||
 | 
					        result="$(curl -sS --oauth2-bearer "${oauth_token}" "${instanceURL}/api/v1/timelines/${timeline:-home}")"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					                                                                                                                                                                
 | 
				
			||||||
 | 
					    # Error checking
 | 
				
			||||||
 | 
					    # Check if the result is a valid JSON
 | 
				
			||||||
 | 
					    if ! echo "$result" | jq '.' >/dev/null 2>&1; then
 | 
				
			||||||
 | 
					        echo "Error: The response from the server was invalid."
 | 
				
			||||||
 | 
					        play_sound error
 | 
				
			||||||
 | 
					        sleep "${interval:-300}"
 | 
				
			||||||
 | 
					        continue
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					                                                                                                                                                                
 | 
				
			||||||
 | 
					    error=$(echo "$result" | jq -r '.error // "null"' 2> /dev/null)
 | 
				
			||||||
 | 
					    if [[ "${error:-null}" != "null" ]]; then
 | 
				
			||||||
 | 
					        echo "Error fetching ${timeline:-home} timeline: $error"
 | 
				
			||||||
 | 
					        play_sound error
 | 
				
			||||||
 | 
					        sleep "${interval:-300}"
 | 
				
			||||||
 | 
					        continue
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					                                                                                                                                                                
 | 
				
			||||||
 | 
					   # process the response to get the latest event id
 | 
				
			||||||
 | 
					    latest_id="$(jq -r '.data[0].id' <<< "$result")"
 | 
				
			||||||
 | 
					    if [[ "${since_id}" != "${latest_id}" ]]; then
 | 
				
			||||||
 | 
					        # handle new events
 | 
				
			||||||
 | 
					        events="$(jq -r '.data[] | "\(.account.username): \(.content)"' <<< "$result")"
 | 
				
			||||||
 | 
					        echo -e "$events" | while read -r event; do
 | 
				
			||||||
 | 
					            echo "$event"
 | 
				
			||||||
 | 
					            echo
 | 
				
			||||||
 | 
					        done
 | 
				
			||||||
 | 
					        since_id="$latest_id"
 | 
				
			||||||
 | 
					    fi
 | 
				
			||||||
 | 
					                                                                                                                                                                
 | 
				
			||||||
 | 
					    sleep "${interval:-300}"
 | 
				
			||||||
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
exit 0
 | 
					exit 0
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user