import random | import random | ||||
import discord | |||||
from pprint import pprint | |||||
from libs.scrapper.scrapper import scrapper | from libs.scrapper.scrapper import scrapper | ||||
from discord.ext.commands import bot | from discord.ext.commands import bot | ||||
choice = random.choice(options) | choice = random.choice(options) | ||||
subreddit += choice | subreddit += choice | ||||
html = requests.get("https://reddit.com/r/"+subreddit, headers = {'User-agent': 'RoxBot Discord Bot'}) | html = requests.get("https://reddit.com/r/"+subreddit, headers = {'User-agent': 'RoxBot Discord Bot'}) | ||||
reddit = html.json()["data"]["children"] | |||||
try: | |||||
reddit = html.json()["data"]["children"] | |||||
except KeyError: | |||||
return False | |||||
return reddit | return reddit | ||||
def retriveurl(self, url): | def retriveurl(self, url): |
if "imgur" in img["src"]: | if "imgur" in img["src"]: | ||||
if not img["src"] in links: | if not img["src"] in links: | ||||
links.append(img["src"]) | 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: | if len(links) > 1: | ||||
return url | return url | ||||
else: | else: |