Skip to content

Commit

Permalink
0.6.2
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoSa-2000 committed Jun 5, 2023
1 parent 9820ec6 commit f44b7a6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
# animegifs.py
<p align="center">
<a href="https://pypi.org/project/animegifs/">
<img src="https://img.shields.io/pypi/dm/animegifs?logo=PyPI&style=for-the-badge" alt="PyPi Downloads"/></a>
<a href="https://discord.gg/TKZJ4GJj2z">
<img src="https://img.shields.io/discord/856005478789677096?logo=Discord&style=for-the-badge" alt="Discord Server"/></a>
<a href="https://pypi.org/project/animegifs/">
<img alt="GitHub release (latest by date)" src="https://img.shields.io/github/v/release/MarcoSa-2000/animegifs?style=for-the-badge"></a>
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/animegifs?logo=Python&logoColor=%23FFFF00&style=for-the-badge">
<img alt="GitHub watchers" src="https://img.shields.io/github/watchers/MarcoSa-2000/animegifs?style=social">
</p>

Get random anime gifs by category. Use Python (intended (for now) for Discord).

WIP - updated in time to time. Versions below v0.5.3 aren't expected to work flawlessly or at all. Version below v0.6 will not have the gifs library updated anymore.
Expand Down Expand Up @@ -89,4 +100,7 @@ malid = gifs.get_malId(gif) #get the ID of the gif's anime myanimelist page.
* Random
* Steal-magic

WIP.
#Troubleshooting and other

If you encounter an error raise an issue on the issue page: https://github.com/MarcoSa-2000/animegifs/issues
or join the discord server to request new categories, new functions, feedback and even errors.
8 changes: 4 additions & 4 deletions animegifs/animegifs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random
from animegifs.distutils import gifs, errors
from mal import Anime
from animegifs.distutils import gifs, errors

class Animegifs:

Expand All @@ -24,7 +24,7 @@ def get_gif(self, category: str) -> str:
"""
if type(category) is int:
raise errors.CategoryIntegral(category)
elif category.lower() in gifs.gifs_name_list:
if category.lower() in gifs.gifs_name_list:
if category.lower() == 'random':
gif_list = []
for key, gif_url in gifs.access().items():
Expand Down Expand Up @@ -57,8 +57,8 @@ def get_mal(self, gif) -> str:
result = gif_name[1]
try:
mal = f"https://myanimelist.net/anime/{int(result)}/"
except ValueError:
raise errors.MethodNotUpdated(gif)
except ValueError as exc:
raise errors.MethodNotUpdated(gif) from exc
return mal
else:
continue
Expand Down
22 changes: 22 additions & 0 deletions animegifs/distutils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,25 @@ def __init__(self, gif, error="Method not yet available for this gif."):
self.gif = gif
self.error = error
super().__init__(self.error)

class AuthTimeout(Exception):
"""
Authentication request timed out. Probably status 504 on server side. Check your connection too.
"""

def __init__(self, exc, error="Authentication request timed out."):
self.exc = exc
self.error = error
super().__init__(self.error)

class AuthError(Exception):
"""
Authentication request returned an error. Probably status error 4xx.
It will be resolved soon, if it persist,
issue an issue on https://github.com/MarcoSa-2000/animegifs/issues.
"""

def __init__(self, exc, error="Authentication request returned an error."):
self.exc = exc
self.error = error
super().__init__(self.error)
15 changes: 13 additions & 2 deletions animegifs/distutils/gifs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import requests
import jwt
from animegifs.distutils import errors

global TOKEN
TOKEN = None
Expand All @@ -24,8 +25,18 @@
'yawn']

def authentication():
response = requests.post("https://enkidu-app-5a3qq2fqya-uc.a.run.app/key1")
auth_key = response.json()['key']
try:
response = requests.post("https://enkidu-app-5a3qq2fqya-uc.a.run.app/key1", timeout=10)
except requests.exceptions.Timeout:
try:
response = requests.post("https://enkidu-app-5a3qq2fqya-uc.a.run.app/key1", timeout=25)
except requests.exceptions.Timeout as exc:
raise errors.AuthTimeout(exc)
if response.status_code == 200:
auth_key = response.json()['key']
else:
exc = response.status_code
raise errors.AuthError(exc)
return auth_key

def access():
Expand Down
5 changes: 4 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
long_description = "\n" + fh.read()

LONG_DESCRIPTION = long_description
VERSION = '0.6.1'
VERSION = '0.6.2'

setup(
name='animegifs',
Expand All @@ -29,7 +29,10 @@
],
python_requires='>=3.8',
classifiers=[
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: Microsoft :: Windows"],
keywords=['anime', 'gif', 'python', 'anime-gif', 'discord'],
Expand Down

0 comments on commit f44b7a6

Please sign in to comment.