-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SomeHybrid/main
3.2.0
- Loading branch information
Showing
6 changed files
with
120 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
atomicwrites==1.4.0 | ||
attrs==21.4.0 | ||
bleach==5.0.0 | ||
colorama==0.4.5 | ||
commonmark==0.9.1 | ||
docutils==0.18.1 | ||
importlib-metadata==4.11.4 | ||
iniconfig==1.1.1 | ||
keyring==23.6.0 | ||
packaging==21.3 | ||
pkginfo==1.8.3 | ||
pluggy==1.0.0 | ||
py==1.11.0 | ||
Pygments==2.12.0 | ||
pyparsing==3.0.9 | ||
pytest==7.1.2 | ||
pywin32-ctypes==0.2.0 | ||
readme-renderer==35.0 | ||
requests==2.28.0 | ||
requests-toolbelt==0.9.1 | ||
rfc3986==2.0.0 | ||
rich==12.4.4 | ||
six==1.16.0 | ||
tomli==2.0.1 | ||
twine==4.0.1 | ||
webencodings==0.5.1 | ||
zipp==3.8.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,16 @@ | ||
atomicwrites==1.4.0 | ||
attrs==21.4.0 | ||
bleach==5.0.0 | ||
certifi==2022.6.15 | ||
charset-normalizer==2.0.12 | ||
colorama==0.4.5 | ||
commonmark==0.9.1 | ||
docutils==0.18.1 | ||
idna==3.3 | ||
importlib-metadata==4.11.4 | ||
iniconfig==1.1.1 | ||
keyring==23.6.0 | ||
packaging==21.3 | ||
pkginfo==1.8.3 | ||
pluggy==1.0.0 | ||
py==1.11.0 | ||
Pygments==2.12.0 | ||
pyparsing==3.0.9 | ||
pytest==7.1.2 | ||
pywin32-ctypes==0.2.0 | ||
readme-renderer==35.0 | ||
requests==2.28.0 | ||
requests-toolbelt==0.9.1 | ||
rfc3986==2.0.0 | ||
rich==12.4.4 | ||
six==1.16.0 | ||
tomli==2.0.1 | ||
twine==4.0.1 | ||
urllib3==1.26.9 | ||
webencodings==0.5.1 | ||
zipp==3.8.0 | ||
certifi>=2022.6.15 | ||
charset-normalizer>=2.0.12 | ||
idna>=3.3 | ||
urllib3>=1.26.9 | ||
charset-normalizer>=2.0 | ||
charset-normalizer<3.0 | ||
multidict>=4.5 | ||
multidict<7.0 | ||
async_timeout>=4.0 | ||
async_timeout<5.0 | ||
asynctest==0.13.0 | ||
yarl>=1.0 | ||
yarl<2.0 | ||
typing_extensions>=3.7.4 | ||
frozenlist>=1.1.1 | ||
aiosignal>=1.1.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,59 @@ | ||
from requests import * | ||
from random import * | ||
import random | ||
import requests | ||
|
||
class xkcd(): | ||
def __init__(self) -> None: | ||
pass | ||
|
||
def random(self = None): | ||
latest_comic_id = request("GET", "https://xkcd.com/info.0.json") | ||
comic_id = randint(1, int(latest_comic_id.json()["num"])) | ||
random_comic = request("GET", f"https://xkcd.com/{comic_id}/info.0.json") | ||
class xkcd: | ||
def __init__(self, async=False, client=None) -> None: | ||
self.current = int(latest_comic_id.json()["num"]) | ||
if async: | ||
self.random = self._arandom | ||
self.get = self._aget | ||
self.latest_comic = self._alatest_comic | ||
self._client = client | ||
|
||
self.__aenter__ = self.enter | ||
self.__aexit__ = self.exit | ||
else: | ||
self.random = self._random | ||
self.get = self._get | ||
self.latest_comic = self._latest_comic | ||
|
||
if client: | ||
raise NotImplementedError | ||
|
||
async def enter(self): | ||
self._client = aiohttp.ClientSession() | ||
return self | ||
|
||
async def exit(self): | ||
await self._client.close() | ||
|
||
def _random(self): | ||
comic_id = random.randint(1, self.current) | ||
random_comic = requests.get(f"https://xkcd.com/{comic_id}/info.0.json") | ||
return random_comic.json() | ||
|
||
def get(id: int): | ||
comic = request("GET", f"https://xkcd.com/{id}/info.0.json") | ||
def _get(self, id: int): | ||
comic = requests.get(f"https://xkcd.com/{id}/info.0.json") | ||
return comic.json() | ||
|
||
def latest_comic(self = None): | ||
comic = request("Get", f"https://xkcd.com/info.0.json") | ||
return comic.json() | ||
def _latest_comic(self): | ||
comic = requests.get(f"https://xkcd.com/info.0.json") | ||
return comic.json() | ||
|
||
async def _arandom(self): | ||
client = self.client if self.client else aiohttp.ClientSession() | ||
comic_id = random.randint(1, self.current) | ||
async with client.get(f"https://xkcd.com/{comic_id}/info.0.json") as random_comic: | ||
return await random_comic.json() | ||
|
||
async def _aget(self, id: int): | ||
client = self.client if self.client else aiohttp.ClientSession() | ||
comic_id = random.randint(1, self.current) | ||
async with client.get(f"https://xkcd.com/{id}/info.0.json") as comic: | ||
return await comic.json() | ||
|
||
async def _alatest_comic(self): | ||
client = self.client if self.client else aiohttp.ClientSession() | ||
comic_id = random.randint(1, self.current) | ||
async with client.get(f"https://xkcd.com/info.0.json") as latest_comic: | ||
return await latest_comic.json() |