Skip to content

Commit

Permalink
Merge pull request #17 from andreiavrammsd/multilanguage-condition
Browse files Browse the repository at this point in the history
Add multilanguage support.
  • Loading branch information
andreiavrammsd authored Jun 29, 2019
2 parents 4beb003 + 515ec36 commit 835b111
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
9 changes: 8 additions & 1 deletion apixu/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ def __init__(self, message, code):


class ApixuClient:
def __init__(self, api_key=None, api_url=API_URL):
def __init__(self, api_key=None, api_url=API_URL, lang=None):
self.api_key = api_key
self.api_url = api_url.rstrip('/')
self.lang = lang

def _get(self, url, args=None):
new_args = {}
Expand Down Expand Up @@ -48,6 +49,8 @@ def current(self, q=None):
args = {}
if q:
args['q'] = q
if self.lang:
args['lang'] = self.lang

return self._get(url, args)

Expand All @@ -68,6 +71,8 @@ def forecast(self, q=None, days=None, hour=None):
args['days'] = days
if hour:
args['hour'] = hour
if self.lang:
args['lang'] = self.lang

return self._get(url, args)

Expand All @@ -84,5 +89,7 @@ def history(self, q=None, since=None, until=None):
if not isinstance(until, datetime.date):
raise ApixuException(message='"until" must be a date', code=0)
args['end_dt'] = until.strftime('%Y-%m-%d')
if self.lang:
args['lang'] = self.lang

return self._get(url, args)
3 changes: 2 additions & 1 deletion examples/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
from apixu.client import ApixuClient

api_key = os.environ['APIXUKEY']
client = ApixuClient(api_key)
client = ApixuClient(api_key=api_key, lang="fr")

current = client.current(q='London')

print(current['location']['name'])
print(current['location']['region'])

print(current['current']['last_updated_epoch'])
print(current['current']['condition']['text'])

'''
{
Expand Down
3 changes: 2 additions & 1 deletion examples/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from apixu.client import ApixuClient

api_key = os.environ['APIXUKEY']
client = ApixuClient(api_key)
client = ApixuClient(api_key=api_key, lang="es")

forecast = client.forecast(q='London', days=2)

print(forecast['location']['name'])

print(forecast['current']['last_updated_epoch'])
print(forecast['current']['condition']['text'])

for day in forecast['forecast']['forecastday']:
print(day['date'])
Expand Down
1 change: 1 addition & 0 deletions examples/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
for day in history['forecast']['forecastday']:
print(day['date'])
print(day['day']['maxtemp_c'])
print(day['day']['condition']['text'])

'''
{
Expand Down

0 comments on commit 835b111

Please sign in to comment.