Last active
July 26, 2023 11:09
-
-
Save furycd001/4bc1e88f662b4d0bd620ce0675a416f4 to your computer and use it in GitHub Desktop.
toots.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env bash | |
INSTANCE="https://fosstodon.org" # Replace with your Mastodon instance URL | |
# Function to fetch and display the timeline | |
function display_timeline { | |
# Fetch the public timeline using curl and the Mastodon API | |
toot_timeline=$(curl -s "$INSTANCE/api/v1/timelines/public" | jq -r '.[] | .content? | gsub("<[^>]*>"; "")' | head -n 20) | |
# Loop through the toot texts and display them | |
while IFS= read -r toot_text; do | |
# If the toot text is empty or only contains spaces, continue to the next toot | |
if [ -z "${toot_text// }" ]; then | |
continue | |
fi | |
# Print the cleaned text-only toot content with a blank line after each toot | |
echo "$toot_text" | |
echo | |
done <<< "$toot_timeline" | |
} | |
# Display the timeline initially | |
display_timeline | |
# Loop to check for new toots | |
while true; do | |
sleep 60 # Wait for 60 seconds before fetching the timeline again | |
clear # Clear the terminal screen | |
# Display the timeline and check for new toots | |
display_timeline | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment