Browse Source

fixed indexerror on the subreddit command.

tags/v1.8.0
Roxie Gibson 6 years ago
parent
commit
ae38dcf492
1 changed files with 13 additions and 18 deletions
  1. +13
    -18
      roxbot/cogs/reddit.py

+ 13
- 18
roxbot/cogs/reddit.py View File

else: else:
if await _imgur_removed(url): if await _imgur_removed(url):
return False return False
page = await roxbot.http.get_page(url)
soup = BeautifulSoup(page, 'html.parser')
links = []
for img in soup.find_all("img"):
if "imgur" in img["src"]:
if not img["src"] in links:
links.append(img["src"])

for video in soup.find_all("source"):
if "imgur" in video["src"]:
if not video["src"] in links:
links.append(video["src"])
if len(links) > 1:
return url

base_endpoint = "https://api.imgur.com/3/"
endpoint_album = base_endpoint + "album/{}/images.json".format(url.split("/")[-1])
endpoint_image = base_endpoint + "image/{}.json".format(url.split("/")[-1])

resp = await roxbot.http.api_request(endpoint_image, headers={"Authorization": "Client-ID {}".format(roxbot.imgur_token)})
if bool(resp["success"]) is True:
return resp["data"]["link"]
else: else:
if "http" not in links[0]:
links[0] = "https:" + links[0]
return links[0]
resp = await roxbot.http.api_request(endpoint_album,
headers={"Authorization": "Client-ID {}".format(roxbot.imgur_token)})
return resp["data"][0]["link"]



# TODO: Reimplement eroshare, eroshae, and erome support.
# TODO: Reimplement eroshare, eroshae, and erome support. Also implement better api interaction with imgur now we require api key




async def subreddit_request(subreddit): async def subreddit_request(subreddit):

Loading…
Cancel
Save