Tweak /sheeb command

This commit is contained in:
Luke Robles 2024-12-10 10:13:02 -08:00
parent d90a1f6a8a
commit b975e78e22
2 changed files with 10 additions and 8 deletions

View File

@ -20,7 +20,6 @@ def get_dog():
def random_sheeb(): def random_sheeb():
# return requests.get("http://shibe.online/api/shibes?count=1&urls=true").json()[0]
return get_from_reddit.get_image(["shiba", "shibe", "shibainu"]) return get_from_reddit.get_image(["shiba", "shibe", "shibainu"])

View File

@ -20,17 +20,20 @@ def get_image(boards, nsfw=False):
if isinstance(boards, list): if isinstance(boards, list):
boards = random.choice(boards) boards = random.choice(boards)
request_string = f"https://reddit.com/r/{boards}/random.json" request_string = f"https://www.reddit.com/r/{boards}/hot.json?raw_json=1"
if not nsfw:
# Append this header to the request. Tells the API to only return SFW results
request_string += "?obey_over18=true"
response = requests.get( response = requests.get(
request_string, headers={"User-agent": random_user_agent} request_string, headers={"User-agent": random_user_agent}
).json()[0]["data"]["children"][0]["data"] ).json()["data"]["children"]
image_url = "https://rxddit.com" + response["permalink"] response = random.choice(response)["data"]
if response.get("url_overridden_by_dest"):
image_url = response["url_overridden_by_dest"]
else:
image_url = response["url"]
# image_url = "https://rxddit.com" + response["permalink"]
if "youtu.be" in response["url"]: if "youtu.be" in response["url"]:
image_url = response["url"] image_url = response["url"]