Skip to content

Commit

Permalink
Merge pull request #14 from uKaigo/add/missing-kumo-methods
Browse files Browse the repository at this point in the history
Add missing kumo methods.
  • Loading branch information
AndyTempel authored Dec 15, 2020
2 parents 2c27a2f + 394132b commit 9d8a379
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ksoftapi/apis/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ async def get_image(self, snowflake: str) -> Image:
return Image(r)

async def search_tags(self, search: str) -> TagCollection:
"""
"""|coro|
This function searchs for tags.
Parameters
Expand Down
58 changes: 57 additions & 1 deletion ksoftapi/apis/kumo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import List, Union

from ..errors import NoResults
from ..models import Location
from ..models import Location, IPInfo, Currency


class Kumo:
Expand Down Expand Up @@ -46,3 +46,59 @@ async def gis(self, location: str, fast: bool = False, more: bool = False, map_z
return [Location(r) for r in result]

return Location(result)

async def geoip(self, ip: str):
"""|coro|
Gets location data from the IP address.
Parameters
----------
ip: :class:`str`
The ip address.
Returns
-------
:class:`IPInfo`
Raises
------
:class:`NoResults`
"""
r = await self._client.http.get('/kumo/geoip', params={'ip': ip})

if r.get('code', 200) == 404:
raise NoResults

result = r['data']
return IPInfo(result)

async def currency(self, from_: str, to: str, value: str):
"""|coro|
Convert a value from one currency to another.
Parameters
----------
from_: :class:`str`
The original currency of the value.
Should match https://en.wikipedia.org/wiki/ISO_4217#Active_codes
to: :class:`str`
The currency to convert to.
Should match https://en.wikipedia.org/wiki/ISO_4217#Active_codes
value: :class:`str`
The value you want to convert.
Returns
-------
:class:`Currency`
Raises
------
:class:`NoResults`
"""
r = await self._client.http.get('/kumo/currency', params={'from': from_, 'to': to, 'value': value})

if r.get('code', 200) == 404:
raise NoResults

result = r['data']
return Currency(result)
28 changes: 22 additions & 6 deletions ksoftapi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def __init__(self, data: dict):
self.bounding_box: List[str] = data['bounding_box']
self.type: List[str] = data['type']
self.map: Optional[str] = data.get('map')

self.raw: dict = data


Expand All @@ -65,7 +64,6 @@ def __init__(self, data: dict):
self.id: str = data['id']
self.search_score: float = data['search_score']
self.url: str = data['url']

self.raw: dict = data


Expand Down Expand Up @@ -106,7 +104,6 @@ def __init__(self, data: dict):
{'name': artist['name'], 'link': artist['link']}
for artist in spotify_artists
]

self.raw: dict = data


Expand All @@ -122,15 +119,13 @@ def __init__(self, data: dict):
self.comments: int = data.get('comments')
self.created_at: int = data.get('created_at')
self.nsfw: bool = data.get('nsfw')

self.raw: dict = data


class Tag:
def __init__(self, data: dict):
self.name: str = data.get('name')
self.nsfw: bool = data.get('nsfw')

self.raw: dict = data

def __str__(self):
Expand All @@ -143,7 +138,6 @@ def __init__(self, data: dict):
self.models: List[Tag] = [Tag(t) for t in self.raw_models]
self.sfw_tags: List[str] = data.get('tags')
self.nsfw_tags: List[str] = data.get('nsfw_tags', [])

self.raw: dict = data

def __len__(self):
Expand Down Expand Up @@ -172,5 +166,27 @@ def __init__(self, data: dict):
self.title: str = data.get('title')
self.nsfw: bool = data.get('nsfw')
self.article_url: str = data.get('article_url')
self.raw: dict = data


class IPInfo:
def __init__(self, data: dict):
self.city: str = data.get('city')
self.continent_code: str = data.get('continent_code')
self.continent_name: str = data.get('continent_name')
self.country_code: str = data.get('country_code')
self.country_name: str = data.get('country_name')
self.dma_code: str = data.get('dma_code')
self.latitude: float = data.get('latitude')
self.longitude: float = data.get('longitude')
self.postal_code: str = data.get('postal_code')
self.region: str = data.get('region')
self.timezone: str = data.get('time_zone')
self.apis: Dict[str, str] = data.get('apis')
self.raw: dict = data


class Currency:
def __init__(self, data: dict):
self.value: float = data.get('value')
self.pretty: str = data.get('pretty')

0 comments on commit 9d8a379

Please sign in to comment.