diff --git a/app/animals.py b/app/animals.py index 77961f2a..225eb537 100755 --- a/app/animals.py +++ b/app/animals.py @@ -20,7 +20,6 @@ def get_dog(): 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"]) diff --git a/app/get_from_reddit.py b/app/get_from_reddit.py index afcc08f7..1740a11d 100755 --- a/app/get_from_reddit.py +++ b/app/get_from_reddit.py @@ -20,17 +20,20 @@ def get_image(boards, nsfw=False): if isinstance(boards, list): boards = random.choice(boards) - request_string = f"https://reddit.com/r/{boards}/random.json" - - if not nsfw: - # Append this header to the request. Tells the API to only return SFW results - request_string += "?obey_over18=true" + request_string = f"https://www.reddit.com/r/{boards}/hot.json?raw_json=1" response = requests.get( 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"]: image_url = response["url"]