save less files
This commit is contained in:
@@ -5,14 +5,8 @@ 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/reddit_bot/$SUBREDDIT.json)
|
||||
# Fetch the JSON feed
|
||||
json=$(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" 2>/dev/null)
|
||||
|
||||
# extract the first item
|
||||
item=$(echo "$json" | jq '.items[0]')
|
||||
@@ -28,11 +22,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/reddit_bot/ # Download the image and save to the output file
|
||||
wget "$image_url" -N -P /tmp/ # 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=@/tmp/reddit_bot/$filename" \
|
||||
-F "file=@/tmp/$filename" \
|
||||
"$INSTANCE_URL/api/v1/media" \
|
||||
| jq -r '.id')
|
||||
|
||||
@@ -57,4 +51,4 @@ curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
"$INSTANCE_URL/api/v1/statuses"
|
||||
fi
|
||||
|
||||
rm -r /tmp/reddit_bot # Remove the Temp Directory
|
||||
rm /tmp/$filename # Delete the Image
|
||||
|
||||
Reference in New Issue
Block a user