diff --git a/ksoftapi/apis/images.py b/ksoftapi/apis/images.py index e35b6ad..e7c67fe 100644 --- a/ksoftapi/apis/images.py +++ b/ksoftapi/apis/images.py @@ -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 diff --git a/ksoftapi/apis/kumo.py b/ksoftapi/apis/kumo.py index cb6bc7c..c017438 100644 --- a/ksoftapi/apis/kumo.py +++ b/ksoftapi/apis/kumo.py @@ -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: @@ -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) diff --git a/ksoftapi/models.py b/ksoftapi/models.py index fa6abd7..96f5fb7 100644 --- a/ksoftapi/models.py +++ b/ksoftapi/models.py @@ -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 @@ -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 @@ -106,7 +104,6 @@ def __init__(self, data: dict): {'name': artist['name'], 'link': artist['link']} for artist in spotify_artists ] - self.raw: dict = data @@ -122,7 +119,6 @@ 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 @@ -130,7 +126,6 @@ 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): @@ -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): @@ -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')