import requests import json from models.xkcdComic import Comic class ProgrammerExcuses: def __init__(self) -> None: self.__url = "http://programmingexcuses.com" def getExcuse(self): page = requests.get(url=self.__url) content = page.content.decode().split("\n") for html in content: if 'href="/"' in html: start_index = html.find('3;">') end_index = html.find("") return html[start_index+4:end_index] class XKCD: def __init__(self) -> None: self.url = "https://xkcd.com" self.__api = "info.0.json" def getRandomComic(self): response = requests.get(url=f"https://c.xkcd.com/random/comic") for line in response.text.split("\n"): if ' None: self.url = "https://www.reddit.com" self.random = "random.json" def _getRandomPost(self, community): response = requests.get(f"{self.url}/{community}/{self.random}") return json.loads(response.text) class RedditProgrammerHumor(Reddit): def __init__(self) -> None: super().__init__() self.community = "r/ProgrammerHumor" def getRandomPost(self): post = self._getRandomPost(self.community) with open(file="data/log/test.json", mode="w") as file: file.write(json.dumps(obj=post, indent=2)) file.close() return post