diff --git a/memes.sh b/memes.sh index 1d67338..8ca8a7b 100644 --- a/memes.sh +++ b/memes.sh @@ -1,11 +1,18 @@ #!/bin/bash -mkdir /tmp/memes -# Fetch the RSS feed and save it to a file -curl -H 'User-Agent: Mozilla/5.0' "https://dhusch.de/rss-bridge/?action=display&bridge=RedditBridge&context=single&r=memes&f=&score=&d=hot&search=&format=Json" > /tmp/memes/memes.json +# Please fill out! +INSTANCE_URL="https://botsin.space" # Mastodon Instance +ACCESS_TOKEN="my_bot_token" # Mastodon Access Token +SUBREDDIT="memes" # Subreddit (must be Image Only, like r/memes) + + +mkdir /tmp/reddit_bot # Make a Temp Directory + +# Fetch the JSON feed and save it to a file +curl -H 'User-Agent: Mozilla/5.0' "https://dhusch.de/rss-bridge/?action=display&bridge=RedditBridge&context=single&r=$SUBREDDIT&f=&score=&d=hot&search=&format=Json" > /tmp/reddit_bot/$SUBREDDIT.json # read the JSON file into a variable -json=$(cat /tmp/memes/memes.json) +json=$(cat /tmp/reddit_bot/$SUBREDDIT.json) # extract the first item item=$(echo "$json" | jq '.items[0]') @@ -21,18 +28,11 @@ content_html=$(echo "$item" | jq -r '.content_html') image_url=$(echo "$content_html" | grep -oP '(?<=src=")[^"]+(?=")') filename=$(basename "$image_url") # Extract the filename from the URL -wget "$image_url" -N -P /tmp/memes/ # Download the image and save to the output file - -# Mastodon instance URL and access token -INSTANCE_URL="https://botsin.space" -ACCESS_TOKEN="my_bot_token" - -# Image to upload -IMAGE_PATH="/tmp/memes/$filename" +wget "$image_url" -N -P /tmp/reddit_bot/ # Download the image and save to the output file # Upload the image and get the media ID MEDIA_ID=$(curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \ - -F "file=@$IMAGE_PATH" \ + -F "file=@/tmp/reddit_bot/$filename" \ "$INSTANCE_URL/api/v1/media" \ | jq -r '.id') @@ -56,3 +56,5 @@ curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \ -F "media_ids[]=$MEDIA_ID" \ "$INSTANCE_URL/api/v1/statuses" fi + +rm -r /tmp/reddit_bot # Remove the Temp Directory