-
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.
Migrate to httpx Async support without aioify Added tests for APIs Added formatter
- Loading branch information
1 parent
9067573
commit 6c47d53
Showing
17 changed files
with
767 additions
and
206 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
dist/ | ||
anipics.egg-info/ | ||
anipics/__pycache__/ | ||
__pycache__/ | ||
.vscode/ | ||
.venv/ | ||
.ruff_cache/ | ||
.pytest_cache/ | ||
|
||
.pypicrc |
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,9 @@ | ||
format: | ||
poetry run black anipics/ tests/ setup.py | ||
poetry run isort --profile black anipics/ tests/ setup.py | ||
poetry run ruff --fix anipics/ tests/ setup.py | ||
|
||
tests: | ||
poetry run pytest tests/ | ||
|
||
.PHONY: format tests |
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,15 +1,10 @@ | ||
# Copyright 2021 D4n13l3k00. | ||
# Copyright 2024 Daniel <D4n13l3k00@yandex.ru>. | ||
# SPDX-License-Identifier: AGPL-3.0-or-later | ||
|
||
__author__ = 'D4n13l3k00' | ||
__version__ = '1.3' | ||
__author__ = "Daniel <D4n13l3k00@yandex.ru>" | ||
__version__ = "1.5" | ||
|
||
from aioify import aioify | ||
__all__ = ["Models", "AniPics", "NekosLife"] | ||
|
||
__all__ = ['Parser', 'asyncParser', 'Models'] | ||
|
||
from .parser import Parser | ||
from .models import Models | ||
|
||
|
||
asyncParser: Parser = aioify(Parser, 'asyncParser') | ||
from .services import AniPics, NekosLife |
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 was deleted.
Oops, something went wrong.
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,4 @@ | ||
__all__ = ["AniPics", "NekosLife"] | ||
|
||
from .anipics import AniPics | ||
from .nekoslife import NekosLife |
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,34 @@ | ||
|
||
import httpx | ||
from bs4 import BeautifulSoup | ||
|
||
from anipics.models import Models | ||
|
||
|
||
class AniPics: | ||
def get(self) -> Models.Result: | ||
"""Get picture from animepicsx.net | ||
Returns: | ||
Models.Result | ||
""" | ||
with httpx.Client() as client: | ||
return Models.Result( | ||
url=BeautifulSoup( | ||
client.get("https://animepicsx.net/random").text, "html.parser" | ||
).find("img")["src"] | ||
) | ||
|
||
async def async_get(self) -> Models.Result: | ||
"""Get picture from animepicsx.net | ||
Returns: | ||
Models.Result | ||
""" | ||
async with httpx.AsyncClient() as client: | ||
return Models.Result( | ||
url=BeautifulSoup( | ||
(await client.get("https://animepicsx.net/random")).text, | ||
"html.parser", | ||
).find("img")["src"] | ||
) |
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,62 @@ | ||
from typing import NewType, Union | ||
|
||
import httpx | ||
|
||
from anipics.models import Models | ||
|
||
NekosLifeType = NewType("NekosLifeType", str) | ||
|
||
|
||
class NekosLife: | ||
class Types: | ||
wallpaper: NekosLifeType = "wallpaper" | ||
ngif: NekosLifeType = "ngif" | ||
tickle: NekosLifeType = "tickle" | ||
feed: NekosLifeType = "feed" | ||
gecg: NekosLifeType = "gecg" | ||
gasm: NekosLifeType = "gasm" | ||
slap: NekosLifeType = "slap" | ||
avatar: NekosLifeType = "avatar" | ||
lizard: NekosLifeType = "lizard" | ||
waifu: NekosLifeType = "waifu" | ||
pat: NekosLifeType = "pat" | ||
_8ball: NekosLifeType = "8ball" | ||
kiss: NekosLifeType = "kiss" | ||
neko: NekosLifeType = "neko" | ||
spank: NekosLifeType = "spank" | ||
cuddle: NekosLifeType = "cuddle" | ||
fox_girl: NekosLifeType = "fox_girl" | ||
hug: NekosLifeType = "hug" | ||
smug: NekosLifeType = "smug" | ||
goose: NekosLifeType = "goose" | ||
woof: NekosLifeType = "woof" | ||
|
||
def get(self, query: Union[NekosLifeType, str]) -> Models.Result: | ||
"""Get picture from nekos.life | ||
Args: | ||
query (NekosLifeType): See Parser/asyncParser.NekosLife.types | ||
Returns: | ||
Models.Result | ||
""" | ||
with httpx.Client() as client: | ||
return Models.Result( | ||
url=client.get(f"https://nekos.life/api/v2/img/{query}").json()["url"] | ||
) | ||
|
||
async def async_get(self, query: Union[NekosLifeType, str]) -> Models.Result: | ||
"""Get picture from nekos.life | ||
Args: | ||
query (NekosLifeType): See Parser/asyncParser.NekosLife.types | ||
Returns: | ||
Models.Result | ||
""" | ||
async with httpx.AsyncClient() as client: | ||
return Models.Result( | ||
url=(await client.get(f"https://nekos.life/api/v2/img/{query}")).json()[ | ||
"url" | ||
] | ||
) |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
from anipics import AniPics, NekosLife | ||
import asyncio | ||
|
||
async def main(): | ||
ap = AniPics() | ||
nl = NekosLife() | ||
|
||
print("AniPics:") | ||
print((await ap.async_get()).url) | ||
|
||
print("NekosLife:") | ||
print((await nl.async_get(NekosLife.Types.avatar)).url) | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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,14 @@ | ||
from anipics import AniPics, NekosLife | ||
|
||
def main(): | ||
ap = AniPics() | ||
nl = NekosLife() | ||
|
||
print("AniPics:") | ||
print(ap.get().url) | ||
|
||
print("NekosLife:") | ||
print(nl.get(NekosLife.Types.avatar).url) | ||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.