Update memes.sh
This commit is contained in:
1 parent
74fdd674e1
commit
3c8bda8552
1 file changed
+15
-13
@@ -1,11 +1,18 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
mkdir /tmp/memes
|
|
||||||
|
|
||||||
# Fetch the RSS feed and save it to a file
|
# Please fill out!
|
||||||
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
|
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
|
# read the JSON file into a variable
|
||||||
json=$(cat /tmp/memes/memes.json)
|
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]')
|
||||||
@@ -21,18 +28,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/memes/ # Download the image and save to the output file
|
wget "$image_url" -N -P /tmp/reddit_bot/ # 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"
|
|
||||||
|
|
||||||
# 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=@$IMAGE_PATH" \
|
-F "file=@/tmp/reddit_bot/$filename" \
|
||||||
"$INSTANCE_URL/api/v1/media" \
|
"$INSTANCE_URL/api/v1/media" \
|
||||||
| jq -r '.id')
|
| jq -r '.id')
|
||||||
|
|
||||||
@@ -56,3 +56,5 @@ curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
|||||||
-F "media_ids[]=$MEDIA_ID" \
|
-F "media_ids[]=$MEDIA_ID" \
|
||||||
"$INSTANCE_URL/api/v1/statuses"
|
"$INSTANCE_URL/api/v1/statuses"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
rm -r /tmp/reddit_bot # Remove the Temp Directory
|
||||||
Reference in new issue
Block a user