Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete rewrite of API #25

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,39 @@ pip install nekos.py
# Usage example
```py
import nekos
print(nekos.cat())

>>> 'https://cdn.nekos.life/meow/04D5A.jpg'
print(nekos.get_neko("meow"))
>>> 'https://cdn.nekos.life/meow/02D1A.jpg'

print(nekos.get_neko("owoify", "Nekos.life is really awesome!"))
>>> 'NYekos.wife is weawwy awesome UwU'
```

# Endpoints
NOTE: You must call them as functions
NOTE: You must call them as function's parameter
- tickle
- slap
- poke
- pat
- neko
- meow
- lizard
- kiss
- fox_girl
- feed
- cuddle
- why
- cat
- eightball
- owoify (Includes parameter `?text=`)
- fact
- img
- owoify
- textcat
- why
- ngif
- smug
- baka
- woof
- spoiler (Includes parameter `?text=`)
- wallpaper
- goose
- gecg
- avatar
- waifu
- 8ball
5 changes: 1 addition & 4 deletions nekos/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
__version__ = "1.1.0"
__version__ = "2.1.0"

from . import dict
from . import http
from .errors import *
from .nekos import *
6 changes: 0 additions & 6 deletions nekos/dict.py

This file was deleted.

22 changes: 0 additions & 22 deletions nekos/errors.py

This file was deleted.

35 changes: 0 additions & 35 deletions nekos/http.py

This file was deleted.

176 changes: 61 additions & 115 deletions nekos/nekos.py
Original file line number Diff line number Diff line change
@@ -1,115 +1,61 @@
import urllib

from . import http, dict, errors

noresponse = "Couldn't contact the API right now..."


def eightball():
r = http.get("/8ball")
return dict.JsonDict({"text": r["response"], "image": r["url"]})


def img(target: str):
possible = [
"wallpaper",
"ngif",
"tickle",
#"lewd", Provides 1 image
"feed",
"gecg",
"gasm",
"slap",
"avatar",
"lizard",
"waifu",
"pat",
"8ball",
"kiss",
"neko",
"spank",
"cuddle",
"fox_girl",
"hug",
"smug",
"goose",
"woof",
]

if target is None:
raise errors.EmptyArgument(
"You have to at least define an argument in string format\nArguments: {}".format(
possible
)
)

if target.lower() not in possible:
raise errors.InvalidArgument(
"You haven't added any valid arguments\nArguments: {}".format(possible)
)

try:
if target.lower() == "random_hentai_gif":
r = http.get("/img/Random_hentai_gif")
else:
r = http.get("/img/" + target.lower())
except Exception:
raise errors.NothingFound(noresponse)

return r["url"]


def owoify(text: str):
if text is None:
raise errors.EmptyArgument(
"You have to enter a string you want to enter to API"
)

r = http.get("/owoify?text=" + urllib.parse.quote(text))
return r["owo"]


def spoiler(text: str):
if text is None:
raise errors.EmptyArgument(
"You have to enter a string you want to enter to API"
)

r = http.get("/spoiler?text=" + urllib.parse.quote(text))
return r["owo"]


def cat():
try:
return http.get("/img/meow")["url"]
except Exception:
raise errors.NothingFound(noresponse)


def textcat():
try:
return http.get("/cat")["cat"]
except Exception:
raise errors.NothingFound(noresponse)


def why():
try:
return http.get("/why")["why"]
except Exception:
raise errors.NothingFound(noresponse)


def fact():
try:
return http.get("/fact")["fact"]
except Exception:
raise errors.NothingFound(noresponse)


def name():
try:
return http.get("/name")["name"]
except Exception:
raise errors.NothingFound(noresponse)

import requests, urllib
from json import loads as json_parse
from json import dumps as json_stringify

APIURL = "https://nekos.life/api/v2"

# ENDPOINTS QUICKDOCS
# [0] - NAME
# [1] - URL
# [2] - JSON GET | {}.get()
ENDPOINTS = [
["tickle", "/img/tickle", "url"],
["slap", "/img/slap", "url"],
["poke", "/img/poke", "url"],
["pat", "/img/pat", "url"],
["neko", "/img/neko", "url"],
["meow", "/img/meow", "url"],
["lizard", "/img/lizard", "url"],
["kiss", "/img/kiss", "url"],
["hug", "/img/hug", "url"],
["fox_girl", "/img/fox_girl", "url"],
["feed", "/img/feed", "url"],
["cuddle", "/img/cuddle", "url"],
["why", "/why", "why"],
["cat", "/cat", "cat"],
["owoify", "/owoify?", "owo"],
["fact", "/fact", "fact"],
["ngif", "/img/ngif", "url"],
["smug", "/img/smug", "url"],
["baka", "/img/baka", "url"],
["woof", "/img/woof", "url"],
["spoiler", "/spoiler?", "owo"],
["wallpaper", "/img/wallpaper", "url"],
["goose", "/img/goose", "url"],
["gecg", "/img/gecg", "url"],
["avatar", "/img/avatar", "url"],
["waifu", "/img/waifu", "url"],
["8ball", "/8ball", "url"]
]

def get_neko(neko_type = str, query_text = str):
typefound = False
nekoindex = 0
for t in ENDPOINTS:
if neko_type == t[0]:
typefound = True
nekoindex = ENDPOINTS.index(t)

if not typefound == True:
return f"Type \"{neko_type}\" not found."
exit()

reqURL = APIURL + eval(f"ENDPOINTS[{nekoindex}][1]")

if ENDPOINTS[nekoindex][1].endswith("?"):
if query_text:
reqURL = f"{reqURL}text={urllib.parse.quote(query_text)}"

req = requests.get(reqURL).content.decode("ascii")
resp = json_parse(req).get(eval(f"ENDPOINTS[{nekoindex}][2]"))
return resp
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@


if not version:
raise RuntimeError("version is not set")
print("version is not set")
return


setup(
Expand Down