Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
eitozx committed Mar 14, 2022
0 parents commit 55bd9e2
Show file tree
Hide file tree
Showing 12 changed files with 939 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# [Useless Files]
*/__pycache__/
*pyc

# [Virtual Environment]
.venv

# [Build Files]
animu.egg-info
build
dist

# [Test Files]
test.py
673 changes: 673 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Animu
An async wrapper for [Animu API](https://animu.ml/) written in Python.

## Key Features
- An async library.
- Anime fact, waifu & more!
- Especially made for discord bots.
- Easy to use with an object oriented design.


## Installing

**Python 3.8 or higher is required**

You can install it by following command:

```cmd
pip install animu
```


# FAQ

## How do I get the Animu API token?
To get the token, [join Discord server of Animu API](https://discord.gg/yyW389c). Move to `#bot-commands` channel. And do `-claim`.

From there, further process should start in your DM. Good luck!

## My Token is not working anymore. Why?
Make sure that you've joined the support server, or else it won't work. If it's still not working, please ask for help in their official server.

## Any examples?
Check [examples](https://github.com/EitoZX/Animu/examples/) folder for examples.

## Any ratelimit?
Yes, 5 requests/second.

## Related Links

- [Official Animu API Discord Server](https://discord.gg/yyW389c)
19 changes: 19 additions & 0 deletions animu/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
Animu API Wrapper
~~~~~~~~~~~~~~~~~~~
A basic wrapper for the Animu API.
Copyright (c) 2022-present EitoZX (Eito)
LICENSE: GNU GPLv3, see LICENSE for more details.
"""

__title__ = 'animu'
__author__ = "EitoZX (Eito)"
__license__ = 'GNU GPLv3'
__copyright__ = 'Copyright (c) 2022-present EitoZX (Eito)'
__version__ = "0.1.0"


from animu.client import Client
33 changes: 33 additions & 0 deletions animu/client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import aiohttp
from animu import model

class Client:
def __init__(self, token: str):
self._header = {"Auth": token}
self._baseurl = "https://animu.ml/api/"

async def _endpoint(self, endpoint: str):
async with aiohttp.ClientSession() as session:
response = await session.get(f"{self._baseurl}{endpoint}", headers=self._header)
result = await response.json(content_type="application/json")
return result

async def fact(self):
data = await self._endpoint('fact')
return model.Fact(data)

async def password(self):
data = await self._endpoint('password')
return model.Password(data)

async def quote(self):
data = await self._endpoint('quote')
return model.Quote(data)

async def roleplay(self, query: str):
data = await self._endpoint(query)
return model.Roleplay(data)

async def waifu(self):
data = await self._endpoint('waifu')
return model.Waifu(data)
66 changes: 66 additions & 0 deletions animu/model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
class Base:
def __init__(self, data):
self._data = data

def __getitem__(self, key):
return self._data[key]

def __str__(self):
return str(self._data)


class Fact(Base):
def __init__(self, data):
super().__init__(data)

self.id = data.get('_id')
self.fact = data.get('fact')
self.tags = data.get('tags')


class Password(Base):
def __init__(self, data):
super().__init__(data)

self.password = data.get('pass')


class Quote(Base):
def __init__(self, data):
super().__init__(data)

self.id = data.get('_id')
self.quote = data.get('quote')
self.anime = data.get('anime')
self.said = data.get('said')


class Roleplay(Base):
def __init__(self, data):
super().__init__(data)

self.url = data.get('url')


class Waifu(Base):
def __init__(self, data):
super().__init__(data)

self.id = data.get('_id')
self.images = data.get('images')

self.names = data.get('names')
self.en_name = self.names.get('en')
self.jp_name = self.names.get('jp')
self.alt_name = self.names.get('alt')

self.animeinfo = data['from']
self.anime = self.animeinfo.get('name')
self.anime_type = self.animeinfo.get('type')

self.statistics = data.get('statistics')
self.fav = self.statistics.get('fav')
self.love = self.statistics.get('love')
self.hate = self.statistics.get('hate')
self.upvote = self.statistics.get('upvote')
self.downvote = self.statistics.get('downvote')
22 changes: 22 additions & 0 deletions examples/discordbot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
This is just an example;
"""

import animu
from discord.ext import commands

bot = commands.Bot(command_prefix='!')
token = 'ANIMU API TOKEN'

@bot.event
async def on_ready():
print(f'{bot.user.name} has connected to Discord!')

@bot.command()
async def test(ctx):
client = animu.Client(token)
object = await client.fact()
await ctx.send(object.fact)


bot.run('DISCORD BOT TOKEN')
16 changes: 16 additions & 0 deletions examples/roleplay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
token = 'ANIMU API TOKEN'

import animu
import asyncio

async def test():

client = animu.Client(token)
object = await client.roleplay("angry")
"""
Here 'angry' is the endpoint, to get the list of roleplay endpoitns
Please give a look at the API docs
"""
print(object)

asyncio.get_event_loop().run_until_complete(test())
25 changes: 25 additions & 0 deletions examples/waifu.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
token = 'ANIMU API TOKEN'

import animu
import asyncio

async def test():
client = animu.Client(token)
test = await client.waifu()
print(test.id)
print(test.images)
print(test.names)
print(test.en_name)
print(test.jp_name)
print(test.alt_name)
print(test.animeinfo)
print(test.anime)
print(test.anime_type)
print(test.statistics)
print(test.fav)
print(test.love)
print(test.hate)
print(test.upvote)
print(test.downvote)

asyncio.get_event_loop().run_until_complete(test())
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
aiohttp
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
28 changes: 28 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import setuptools
import animu

version = animu.__version__
author = animu.__author__

requirements = []
with open('requirements.txt') as f:
requirements = f.read().splitlines()

with open("README.md", "r") as f:
long_description = f.read()


setuptools.setup(
name = "animu",
author = author,
author_email = "[email protected]",
url = "http://github.com/EitoZX/Animu",
version = version,
description = "An async wrapper for Animu API written in Python.",
long_description = long_description,
long_description_content_type = "text/markdown",
packages = setuptools.find_packages(),
license_files = "LICENSE",
install_requires = requirements,
keywords = ['animu-api','anime','anime-quotes', 'anime-api', 'animeapi', 'animu', 'anime-quotes-api',],
)

0 comments on commit 55bd9e2

Please sign in to comment.