save less files
This commit is contained in:
1 parent
3c8bda8552
commit
2706c07d0f
1 file changed
+5
-11
@@ -5,14 +5,8 @@ INSTANCE_URL="https://botsin.space" # Mastodon Instance
|
|||||||
ACCESS_TOKEN="my_bot_token" # Mastodon Access Token
|
ACCESS_TOKEN="my_bot_token" # Mastodon Access Token
|
||||||
SUBREDDIT="memes" # Subreddit (must be Image Only, like r/memes)
|
SUBREDDIT="memes" # Subreddit (must be Image Only, like r/memes)
|
||||||
|
|
||||||
|
# Fetch the JSON feed
|
||||||
mkdir /tmp/reddit_bot # Make a Temp Directory
|
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)
|
||||||
|
|
||||||
# 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)
|
|
||||||
|
|
||||||
# extract the first item
|
# extract the first item
|
||||||
item=$(echo "$json" | jq '.items[0]')
|
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=")[^"]+(?=")')
|
image_url=$(echo "$content_html" | grep -oP '(?<=src=")[^"]+(?=")')
|
||||||
|
|
||||||
filename=$(basename "$image_url") # Extract the filename from the URL
|
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
|
# Upload the image and get the media ID
|
||||||
MEDIA_ID=$(curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
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" \
|
"$INSTANCE_URL/api/v1/media" \
|
||||||
| jq -r '.id')
|
| jq -r '.id')
|
||||||
|
|
||||||
@@ -57,4 +51,4 @@ curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
|||||||
"$INSTANCE_URL/api/v1/statuses"
|
"$INSTANCE_URL/api/v1/statuses"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -r /tmp/reddit_bot # Remove the Temp Directory
|
rm /tmp/$filename # Delete the Image
|
||||||
Reference in new issue
Block a user