Skip to content

Commit

Permalink
0.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoSa-2000 committed Jun 1, 2023
1 parent 03c11ea commit a8a0239
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 12 deletions.
40 changes: 37 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
# animegifs.py
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.
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.

`pip install animegifs`

# HOW TO USE

```py
#v0.5.3>
from animegifs import animegifs

gifs = animegifs.Animegifs()

gif = gifs.get_gif(category) #return the url of the gif.
```

```py
#v0.6>
from animegifs import animegifs

gifs = animegifs.Animegifs()

gif = gifs.get_gif(category)
gif = gifs.get_gif(category) #return the url of the gif.
mal = gifs.get_mal(gif) #get url of the gif's anime myanimelist page.
title = gifs.get_animetitle(gif) #get the title of the gif's anime.
malid = gifs.get_malId(gif) #get the ID of the gif's anime myanimelist page.
```

**Category list:**
Expand Down Expand Up @@ -46,5 +57,28 @@ gif = gifs.get_gif(category)
* Marry
* Nosebleed
* Nuzzle
* Pat
* Peck
* Poke
* Popcorn
* Pout
* Punch
* Punish
* Run
* Sad
* Scared
* Shoot
* Shrug
* Sip
* Slap
* Smirk
* Sorry
* Spank
* Stare

**Special Category List**

* Random
* Steal-magic

WIP.
78 changes: 74 additions & 4 deletions animegifs/animegifs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
from animegifs.distutils import gifs, errors
from mal import Anime

class Animegifs:

Expand All @@ -14,19 +15,88 @@ def get_gif(self, category: str) -> str:
category (str): Valid categories: attack, bite, bloodsuck, blush, bonk,
brofist, cry, cuddle, dance, disgust, facedesk, facepalm, flick, flirt,
handhold, happy, harass, highfive, hug, icecream, insult, kill, kiss,
lick, love, marry, nosebleed, nuzzle.
lick, love, marry, nosebleed, nuzzle, pat, peck, poke, popcorn, pout,
punch, punish, random, run, sad, scared, shoot, shrug, sip, slap, smirk,
sorry, spank, stare.
Returns:
gif: gif (url) -> str
"""
if type(category) is int:
raise errors.CategoryIntegral(category)
elif category.lower() in gifs.gifs_name_list:
gifs_list = gifs.access()[category.lower()]
gif = random.choice(gifs_list)
if category.lower() == 'random':
gif_list = []
for key, gif_url in gifs.access().items():
for urls in gif_url:
gif_list.append(urls[0])
gif = gif_list
else:
gifs_list = gifs.access()[category.lower()]
gif = [gif_url[0] for gif_url in gifs_list]
gif = random.choice(gif)
elif category.lower() not in gifs.gifs_name_list:
raise errors.CategoryError(category)
else:
raise errors.CategoryUnknown(category)
return gif


def get_mal(self, gif) -> str:
"""
Return the myanimelist page of the gif's anime.
Args:
gif (url: str)
Returns:
mal: mal (url) -> str
"""
for key, gif_url in gifs.access().items():
for gif_name in gif_url:
if gif_name[0] == gif:
result = gif_name[1]
try:
mal = f"https://myanimelist.net/anime/{int(result)}/"
except ValueError:
raise errors.MethodNotUpdated(gif)
return mal
else:
continue

def get_malId(self, gif) -> int:
"""
Return the myanimelist ID of the gif's anime.
Args:
gif (url: str)
Returns:
malid: malId -> int
"""
for key, gif_url in gifs.access().items():
for gif_name in gif_url:
if gif_name[0] == gif:
result = gif_name[1]
malid = int(result)
return malid
else:
continue

def get_animetitle(self, gif) -> str:
"""
Return the title of the gif's anime.
Args:
gif (url: str)
Returns:
title: title -> str
"""
for key, gif_url in gifs.access().items():
for gif_name in gif_url:
if gif_name[0] == gif:
result = gif_name[1]
title = Anime(int(result)).title
return title
else:
continue
11 changes: 11 additions & 0 deletions animegifs/distutils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ def __init__(self, category, error="Not a valid category."):
self.category = category
self.error = error
super().__init__(self.error)

class MethodNotUpdated(Exception):
"""
The method for get the gif's <title, mal link, mal id> is not yet supported for that gif url.
Usually means is just in work in progress and will be available soon.
"""

def __init__(self, gif, error="Method not yet available for this gif."):
self.gif = gif
self.error = error
super().__init__(self.error)
27 changes: 24 additions & 3 deletions animegifs/distutils/gifs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import json
import requests
import jwt

global TOKEN
TOKEN = None
gifs_name_list = ["attack",
"bite", 'bloodsuck', 'blush', 'bonk', 'brofist',
'cry', 'cuddle',
Expand All @@ -11,10 +14,28 @@
'kill', 'kiss',
'lick', 'love',
'marry',
'nosebleed', 'nuzzle']
'nosebleed', 'nuzzle',
'pat', 'peck', 'poke', 'popcorn', 'pout', 'punch', 'punish',
'random', 'run',
'sad', 'scared', 'shoot', 'shrug', 'sip', 'slap', 'smirk', 'sorry', 'spank', 'stare']

def authentication():
response = requests.post("https://enkidu-app-5a3qq2fqya-uc.a.run.app/key1")
auth_key = response.json()['key']
return auth_key

def access():
data = requests.get("https://objectstorage.eu-frankfurt-1.oraclecloud.com/p/zDPowf1lXXMMpXzo_Lnb31IOtUyxrtD-kDS7fpKxLuCYnR5xr-171Tyz0tW0EhKV/n/frqs54dqeajn/b/animegifs_lib/o/gifs.json").content
data = json.loads(data)
global TOKEN
if TOKEN:
data = jwt.decode(TOKEN, "enkidu-key", algorithms="HS512")
data = list(data.keys())
data = requests.get(data[0]).content
data = json.loads(data)
else:
TOKEN = authentication()
data = jwt.decode(TOKEN, "enkidu-key", algorithms="HS512")
data = list(data.keys())
data = requests.get(data[0]).content
data = json.loads(data)

return data
6 changes: 4 additions & 2 deletions 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.5.4'
VERSION = '0.6.0'

setup(
name='animegifs',
Expand All @@ -23,7 +23,9 @@
license='MIT',
url="https://github.com/MarcoSa-2000/animegifs",
install_requires=[
'requests==2.28.2,<=2.29.0'
'requests==2.28.2,<=2.29.0',
'mal-api==0.5.3',
'PyJWT>=2.4.0,<=2.7.0'
],
python_requires='>=3.8',
classifiers=[
Expand Down

0 comments on commit a8a0239

Please sign in to comment.