Skip to content

Instantly share code, notes, and snippets.

@furycd001
Last active July 26, 2023 11:09
Show Gist options
  • Select an option

  • Save furycd001/4bc1e88f662b4d0bd620ce0675a416f4 to your computer and use it in GitHub Desktop.

Select an option

Save furycd001/4bc1e88f662b4d0bd620ce0675a416f4 to your computer and use it in GitHub Desktop.

Revisions

  1. furycd001 revised this gist Jul 26, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    #!/bin/bash
    #!/bin/env bash

    INSTANCE="https://your-mastodon-instance" # Replace with your Mastodon instance URL
    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 5)
    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
    @@ -31,4 +31,4 @@ while true; do

    # Display the timeline and check for new toots
    display_timeline
    done
    done
  2. furycd001 created this gist Jul 26, 2023.
    34 changes: 34 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #!/bin/bash

    INSTANCE="https://your-mastodon-instance" # 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 5)

    # 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