diff --git a/apixu/client.py b/apixu/client.py index 034f71f..5c7d61a 100644 --- a/apixu/client.py +++ b/apixu/client.py @@ -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 = {} @@ -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) @@ -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) @@ -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) diff --git a/examples/current.py b/examples/current.py index d643550..07a7906 100644 --- a/examples/current.py +++ b/examples/current.py @@ -3,7 +3,7 @@ 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') @@ -11,6 +11,7 @@ print(current['location']['region']) print(current['current']['last_updated_epoch']) +print(current['current']['condition']['text']) ''' { diff --git a/examples/forecast.py b/examples/forecast.py index 19910fb..b42eb5c 100644 --- a/examples/forecast.py +++ b/examples/forecast.py @@ -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']) diff --git a/examples/history.py b/examples/history.py index 3c04347..2a68663 100644 --- a/examples/history.py +++ b/examples/history.py @@ -14,6 +14,7 @@ for day in history['forecast']['forecastday']: print(day['date']) print(day['day']['maxtemp_c']) + print(day['day']['condition']['text']) ''' {