Skip to content

Commit 9d8a379

Browse files
authored
Merge pull request #14 from uKaigo/add/missing-kumo-methods
Add missing kumo methods.
2 parents 2c27a2f + 394132b commit 9d8a379

File tree

3 files changed

+80
-8
lines changed

3 files changed

+80
-8
lines changed

ksoftapi/apis/images.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ async def get_image(self, snowflake: str) -> Image:
128128
return Image(r)
129129

130130
async def search_tags(self, search: str) -> TagCollection:
131-
"""
131+
"""|coro|
132132
This function searchs for tags.
133133
134134
Parameters

ksoftapi/apis/kumo.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import List, Union
22

33
from ..errors import NoResults
4-
from ..models import Location
4+
from ..models import Location, IPInfo, Currency
55

66

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

4848
return Location(result)
49+
50+
async def geoip(self, ip: str):
51+
"""|coro|
52+
Gets location data from the IP address.
53+
54+
Parameters
55+
----------
56+
ip: :class:`str`
57+
The ip address.
58+
59+
Returns
60+
-------
61+
:class:`IPInfo`
62+
63+
Raises
64+
------
65+
:class:`NoResults`
66+
"""
67+
r = await self._client.http.get('/kumo/geoip', params={'ip': ip})
68+
69+
if r.get('code', 200) == 404:
70+
raise NoResults
71+
72+
result = r['data']
73+
return IPInfo(result)
74+
75+
async def currency(self, from_: str, to: str, value: str):
76+
"""|coro|
77+
Convert a value from one currency to another.
78+
79+
Parameters
80+
----------
81+
from_: :class:`str`
82+
The original currency of the value.
83+
Should match https://en.wikipedia.org/wiki/ISO_4217#Active_codes
84+
to: :class:`str`
85+
The currency to convert to.
86+
Should match https://en.wikipedia.org/wiki/ISO_4217#Active_codes
87+
value: :class:`str`
88+
The value you want to convert.
89+
90+
Returns
91+
-------
92+
:class:`Currency`
93+
94+
Raises
95+
------
96+
:class:`NoResults`
97+
"""
98+
r = await self._client.http.get('/kumo/currency', params={'from': from_, 'to': to, 'value': value})
99+
100+
if r.get('code', 200) == 404:
101+
raise NoResults
102+
103+
result = r['data']
104+
return Currency(result)

ksoftapi/models.py

+22-6
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ def __init__(self, data: dict):
4646
self.bounding_box: List[str] = data['bounding_box']
4747
self.type: List[str] = data['type']
4848
self.map: Optional[str] = data.get('map')
49-
5049
self.raw: dict = data
5150

5251

@@ -65,7 +64,6 @@ def __init__(self, data: dict):
6564
self.id: str = data['id']
6665
self.search_score: float = data['search_score']
6766
self.url: str = data['url']
68-
6967
self.raw: dict = data
7068

7169

@@ -106,7 +104,6 @@ def __init__(self, data: dict):
106104
{'name': artist['name'], 'link': artist['link']}
107105
for artist in spotify_artists
108106
]
109-
110107
self.raw: dict = data
111108

112109

@@ -122,15 +119,13 @@ def __init__(self, data: dict):
122119
self.comments: int = data.get('comments')
123120
self.created_at: int = data.get('created_at')
124121
self.nsfw: bool = data.get('nsfw')
125-
126122
self.raw: dict = data
127123

128124

129125
class Tag:
130126
def __init__(self, data: dict):
131127
self.name: str = data.get('name')
132128
self.nsfw: bool = data.get('nsfw')
133-
134129
self.raw: dict = data
135130

136131
def __str__(self):
@@ -143,7 +138,6 @@ def __init__(self, data: dict):
143138
self.models: List[Tag] = [Tag(t) for t in self.raw_models]
144139
self.sfw_tags: List[str] = data.get('tags')
145140
self.nsfw_tags: List[str] = data.get('nsfw_tags', [])
146-
147141
self.raw: dict = data
148142

149143
def __len__(self):
@@ -172,5 +166,27 @@ def __init__(self, data: dict):
172166
self.title: str = data.get('title')
173167
self.nsfw: bool = data.get('nsfw')
174168
self.article_url: str = data.get('article_url')
169+
self.raw: dict = data
170+
175171

172+
class IPInfo:
173+
def __init__(self, data: dict):
174+
self.city: str = data.get('city')
175+
self.continent_code: str = data.get('continent_code')
176+
self.continent_name: str = data.get('continent_name')
177+
self.country_code: str = data.get('country_code')
178+
self.country_name: str = data.get('country_name')
179+
self.dma_code: str = data.get('dma_code')
180+
self.latitude: float = data.get('latitude')
181+
self.longitude: float = data.get('longitude')
182+
self.postal_code: str = data.get('postal_code')
183+
self.region: str = data.get('region')
184+
self.timezone: str = data.get('time_zone')
185+
self.apis: Dict[str, str] = data.get('apis')
176186
self.raw: dict = data
187+
188+
189+
class Currency:
190+
def __init__(self, data: dict):
191+
self.value: float = data.get('value')
192+
self.pretty: str = data.get('pretty')

0 commit comments

Comments
 (0)