Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
csparpa committed Sep 23, 2020
2 parents 33a7662 + eb1f943 commit 26bf1cf
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 12 deletions.
9 changes: 6 additions & 3 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,24 @@ Contributors will be shown in alphabetical order
Code
----
* [alechewitt](https://github.com/alechewitt)
* [camponez](https://github.com/camponez)
* [Darumin](https://github.com/Darumin)
* [dev-iks](https://github.com/dev-iks)
* [dphildebrandt](https://github.com/dphildebrandt)
* [dstmar](https://github.com/dstmar)
* [edenhaus](https://github.com/edenhaus)
* [eumiro](https://github.com/eumiro)
* [ggstuart](https://github.com/ggstuart)
* [jwmelvin](https://github.com/jwmelvin)
* [lardconcepts](https://github.com/lardconcepts)
* [liato](https://github.com/liato)
* [LukasBoersma](https://github.com/LukasBoersma)
* [Misiu](https://github.com/Misiu)
* [Noid](https://github.com/n0id)
* [titilambert](https://github.com/titilambert)
* [txemi](https://github.com/txemi)
* [camponez](https://github.com/camponez)
* [dev-iks](https://github.com/dev-iks)
* [eumiro](https://github.com/eumiro)

* [Wesley-Vos](https://github.com/Wesley-Vos)

Docs
----
Expand Down
51 changes: 51 additions & 0 deletions pyowm/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,54 @@
STATIONS_API_VERSION = (3, 0, 0)
UVINDEX_API_VERSION = (3, 0, 0)
WEATHER_API_VERSION = (2, 5, 0)
LANGUAGES = [
"af",
"al",
"ar",
"az",
"bg",
"ca",
"cz",
"da",
"de",
"el",
"en",
"es",
"eu",
"fa",
"fi",
"fr",
"gl",
"he",
"hi",
"hr",
"hu",
"id",
"it",
"ja",
"kr",
"la",
"lt",
"mk",
"nl",
"no",
"pl",
"pt",
"pt_br",
"ro",
"ru",
"se",
"sk",
"sl",
"sp",
"sr",
"sv",
"th",
"tr",
"ua",
"uk",
"vi",
"zh_cn",
"zh_tw",
"zu",
]
10 changes: 10 additions & 0 deletions pyowm/owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ def version(self):
"""
return constants.PYOWM_VERSION

@property
def supported_languages(self):
"""
Returns the languages that the OWM API supports
:return: `list` of `str`
"""
return constants.LANGUAGES

def agro_manager(self):
"""
Gives a `pyowm.agro10.agro_manager.AgroManager` instance that can be used to read/write data from the
Expand Down
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
STATION_WEATHER_HISTORY_URI = 'history/station'
ONE_CALL_URI = 'onecall'
ONE_CALL_HISTORICAL_URI = ONE_CALL_URI + '/timemachine'
ICONS_BASE_URI = 'http://openweathermap.org/img/wn/%s.png'
ICONS_BASE_URI = 'http://openweathermap.org/img/wn/%s%s.png'
8 changes: 6 additions & 2 deletions pyowm/weatherapi25/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,17 @@ def visibility(self, unit='meters'):
else:
raise ValueError('Invalid value for target visibility distance unit')

def weather_icon_url(self):
def weather_icon_url(self, size=""):
"""Returns weather-related icon URL as a string.
:param size: the size of the icon, normal (default, like the old ones), 2x or 4x
:type size: str
:returns: the icon URL.
"""
return ICONS_BASE_URI % self.weather_icon_name
size = ("@" if size != "" else "") + size
return ICONS_BASE_URI % (self.weather_icon_name, size)

def __repr__(self):
return "<%s.%s - reference_time=%s, status=%s, detailed_status=%s>" % (
Expand Down
13 changes: 10 additions & 3 deletions sphinx/v3/code-recipes.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,21 @@ owm = OWM('your-api-key', config_dict)
```

### Language setting
English is the default - but you can change it
Check out [https://openweathermap.org/current](https://openweathermap.org/current) for the complete list of supported languages
The list of supported languages is given by:
```python
from pyowm.owm import OWM
owm = OWM('your-api-key')
owm.supported_languages
```
Check out [https://openweathermap.org/current](https://openweathermap.org/current) for reference on supported languages

English is the default language on the OWM API - but you can change it:

```python
from pyowm.owm import OWM
from pyowm.utils.config import get_default_config
config_dict = get_default_config()
config_dict['language'] = 'pt' # your language here
config_dict['language'] = 'pt' # your language here, eg. Portuguese
owm = OWM('your-api-key', config_dict)
```

Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def test_properties(self):
version = self.__test_instance.version
self.assertIsInstance(version, tuple)

languages = self.__test_instance.supported_languages
self.assertIsInstance(languages, list)
self.assertTrue(all([isinstance(lang, str) for lang in languages]))

config = self.__test_instance.configuration
self.assertIsInstance(config, dict)

Expand Down
12 changes: 9 additions & 3 deletions tests/unit/weatherapi25/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,9 +557,15 @@ def test_visibility_fails_with_unknown_units(self):
self.assertRaises(ValueError, Weather.visibility, self.__test_instance, 'xyz')

def test_weather_icon_url(self):
expected = ICONS_BASE_URI % self.__test_instance.weather_icon_name
result = self.__test_instance.weather_icon_url()
self.assertEqual(expected, result)
expected_unspecified = ICONS_BASE_URI % (self.__test_instance.weather_icon_name, "")
expected_2x = ICONS_BASE_URI % (self.__test_instance.weather_icon_name, "@2x")
expected_4x = ICONS_BASE_URI % (self.__test_instance.weather_icon_name, "@4x")
result_unspecified = self.__test_instance.weather_icon_url()
result_2x = self.__test_instance.weather_icon_url(size="2x")
result_4x = self.__test_instance.weather_icon_url(size="4x")
self.assertEqual(expected_unspecified, result_unspecified)
self.assertEqual(expected_2x, result_2x)
self.assertEqual(expected_4x, result_4x)

def test_repr(self):
print(self.__test_instance)
Expand Down

0 comments on commit 26bf1cf

Please sign in to comment.