Skip to content

Commit

Permalink
Updated OneCall API to v3.0 (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeThomson authored Nov 8, 2024
1 parent 1a12151 commit dcef9c5
Show file tree
Hide file tree
Showing 52 changed files with 84 additions and 83 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Code
* [eumiro](https://github.com/eumiro)
* [ggstuart](https://github.com/ggstuart)
* [irahorecka](https://github.com/irahorecka)
* [JakeThomson](https://github.com/jakethomson)
* [jwmelvin](https://github.com/jwmelvin)
* [lardconcepts](https://github.com/lardconcepts)
* [liato](https://github.com/liato)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PyOWM runs on Python 3.7+
### What kind of data can I get with PyOWM ?
With PyOWM you can integrate into your code any of the following OpenWeatherMap web APIs:

- **Weather API v2.5** + **OneCall API**, providing current weather data, weather forecasts, weather history
- **Weather API v3.0** + **OneCall API**, providing current weather data, weather forecasts, weather history
- **Agro API v1.0**, providing soil data and satellite imagery search and download
- **Air Pollution API v3.0**, providing data about CO, O3, NO2 and SO2
- **UV Index API v3.0**, providing data about Ultraviolet exposition
Expand Down
2 changes: 1 addition & 1 deletion pyowm/airpollutionapi30/airstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pyowm.commons import exceptions
from pyowm.utils import formatting, timestamps
from pyowm.weatherapi25 import location
from pyowm.weatherapi30 import location


class AirStatus:
Expand Down
2 changes: 1 addition & 1 deletion pyowm/airpollutionapi30/coindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pyowm.commons import exceptions
from pyowm.utils import formatting, timestamps
from pyowm.weatherapi25 import location
from pyowm.weatherapi30 import location


class COIndex:
Expand Down
2 changes: 1 addition & 1 deletion pyowm/airpollutionapi30/no2index.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pyowm.commons import exceptions
from pyowm.utils import formatting, timestamps
from pyowm.weatherapi25 import location
from pyowm.weatherapi30 import location


class NO2Index:
Expand Down
2 changes: 1 addition & 1 deletion pyowm/airpollutionapi30/ozone.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pyowm.commons import exceptions
from pyowm.utils import formatting, timestamps
from pyowm.weatherapi25 import location
from pyowm.weatherapi30 import location


class Ozone:
Expand Down
2 changes: 1 addition & 1 deletion pyowm/airpollutionapi30/so2index.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from pyowm.commons import exceptions
from pyowm.weatherapi25 import location
from pyowm.weatherapi30 import location
from pyowm.utils import formatting, timestamps


Expand Down
2 changes: 1 addition & 1 deletion pyowm/commons/cityidregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import sqlite3
import tempfile
from pkg_resources import resource_filename
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location

CITY_ID_DB_PATH = 'cityids/cities.db.bz2'

Expand Down
2 changes: 1 addition & 1 deletion pyowm/geocodingapi10/geocoding_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pyowm.commons.uris import ROOT_GEOCODING_API_URL, DIRECT_GEOCODING_URI, REVERSE_GEOCODING_URI
from pyowm.constants import GEOCODING_API_VERSION
from pyowm.utils import geo
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location


class GeocodingManager:
Expand Down
6 changes: 3 additions & 3 deletions pyowm/owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pyowm.uvindexapi30 import uvindex_manager
from pyowm.utils import config as cfg
from pyowm.commons import cityidregistry
from pyowm.weatherapi25 import weather_manager
from pyowm.weatherapi30 import weather_manager


class OWM:
Expand Down Expand Up @@ -120,9 +120,9 @@ def uvindex_manager(self):

def weather_manager(self):
"""
Gives a `pyowm.weatherapi25.weather_manager.WeatherManager` instance that can be used to fetch air
Gives a `pyowm.weatherapi30.weather_manager.WeatherManager` instance that can be used to fetch air
pollution data.
:return: a `pyowm.weatherapi25.weather_manager.WeatherManager` instance
:return: a `pyowm.weatherapi30.weather_manager.WeatherManager` instance
"""
return weather_manager.WeatherManager(self.api_key, self.config)

Expand Down
2 changes: 1 addition & 1 deletion pyowm/uvindexapi30/uvindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pyowm.commons import exceptions
from pyowm.utils import formatting, timestamps
from pyowm.weatherapi25 import location
from pyowm.weatherapi30 import location


def uv_intensity_to_exposure_risk(uv_intensity):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

from pyowm.commons import exceptions
from pyowm.utils import timestamps, formatting
from pyowm.weatherapi25 import location
from pyowm.weatherapi25 import weather
from pyowm.weatherapi30 import location
from pyowm.weatherapi30 import weather


class Forecast:
Expand Down Expand Up @@ -89,7 +89,7 @@ def from_dict(cls, the_dict):
if the_dict is None:
raise exceptions.ParseAPIResponseError('JSON data is None')
# Check if server returned errors: this check overcomes the lack of use
# of HTTP error status codes by the OWM API 2.5. This mechanism is
# of HTTP error status codes by the OWM API 3.0. This mechanism is
# supposed to be deprecated as soon as the API fully adopts HTTP for
# conveying errors to the clients
if 'message' in the_dict and 'cod' in the_dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from pyowm.utils import formatting, weather
from pyowm.weatherapi25 import weathercoderegistry
from pyowm.weatherapi30 import weathercoderegistry


class Forecaster:
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import time
from pyowm.commons import exceptions
from pyowm.utils import formatting
from pyowm.weatherapi25 import location
from pyowm.weatherapi25 import weather
from pyowm.weatherapi30 import location
from pyowm.weatherapi30 import weather


class Observation:
Expand Down Expand Up @@ -67,7 +67,7 @@ def from_dict(cls, the_dict):
raise exceptions.ParseAPIResponseError('JSON data is None')

# Check if server returned errors: this check overcomes the lack of use
# of HTTP error status codes by the OWM API 2.5. This mechanism is
# of HTTP error status codes by the OWM API 3.0. This mechanism is
# supposed to be deprecated as soon as the API fully adopts HTTP for
# conveying errors to the clients
if 'message' in the_dict and 'cod' in the_dict:
Expand Down Expand Up @@ -120,7 +120,7 @@ def from_dict_of_lists(self, the_dict):
raise exceptions.ParseAPIResponseError('JSON data is None')
if 'cod' in the_dict:
# Check if server returned errors: this check overcomes the lack of use
# of HTTP error status codes by the OWM API 2.5. This mechanism is
# of HTTP error status codes by the OWM API 3.0. This mechanism is
# supposed to be deprecated as soon as the API fully adopts HTTP for
# conveying errors to the clients
if the_dict['cod'] == "200" or the_dict['cod'] == 200:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pyowm.commons import exceptions
from pyowm.utils import geo
from pyowm.weatherapi25.weather import Weather
from pyowm.weatherapi25.national_weather_alert import NationalWeatherAlert
from pyowm.weatherapi30.weather import Weather
from pyowm.weatherapi30.national_weather_alert import NationalWeatherAlert


class OneCall:
Expand Down Expand Up @@ -69,7 +69,7 @@ def from_dict(cls, the_dict: dict):
raise exceptions.ParseAPIResponseError('Data is None')

# Check if server returned errors: this check overcomes the lack of use
# of HTTP error status codes by the OWM API 2.5. This mechanism is
# of HTTP error status codes by the OWM API 3.0. This mechanism is
# supposed to be deprecated as soon as the API fully adopts HTTP for
# conveying errors to the clients
if 'message' in the_dict and 'cod' in the_dict:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion pyowm/weatherapi25/uris.py → pyowm/weatherapi30/uris.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-


ROOT_WEATHER_API = 'openweathermap.org/data/2.5'
ROOT_WEATHER_API = 'openweathermap.org/data/3.0'
OBSERVATION_URI = 'weather'
GROUP_OBSERVATIONS_URI = 'group'
STATION_URI = 'station'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pyowm.commons import exceptions
from pyowm.utils import formatting, measurables
from pyowm.weatherapi25.uris import ICONS_BASE_URI
from pyowm.weatherapi30.uris import ICONS_BASE_URI


class Weather:
Expand Down Expand Up @@ -508,7 +508,7 @@ def from_dict_of_lists(cls, the_dict):
if the_dict is None:
raise exceptions.ParseAPIResponseError('Data is None')
# Check if server returned errors: this check overcomes the lack of use
# of HTTP error status codes by the OWM API 2.5. This mechanism is
# of HTTP error status codes by the OWM API 3.0. This mechanism is
# supposed to be deprecated as soon as the API fully adopts HTTP for
# conveying errors to the clients
if 'message' in the_dict and 'cod' in the_dict:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from pyowm.commons.http_client import HttpClient
from pyowm.constants import WEATHER_API_VERSION
from pyowm.utils import geo
from pyowm.weatherapi25 import forecaster, historian, observation, forecast, stationhistory, one_call
from pyowm.weatherapi25.uris import ROOT_WEATHER_API, OBSERVATION_URI, GROUP_OBSERVATIONS_URI, FIND_OBSERVATIONS_URI, \
from pyowm.weatherapi30 import forecaster, historian, observation, forecast, stationhistory, one_call
from pyowm.weatherapi30.uris import ROOT_WEATHER_API, OBSERVATION_URI, GROUP_OBSERVATIONS_URI, FIND_OBSERVATIONS_URI, \
BBOX_CITY_URI, THREE_HOURS_FORECAST_URI, DAILY_FORECAST_URI, STATION_WEATHER_HISTORY_URI, ONE_CALL_URI, \
ONE_CALL_HISTORICAL_URI

Expand Down Expand Up @@ -172,7 +172,7 @@ def weather_at_places(self, pattern, searchtype, limit=None):
raise ValueError("'limit' must be None or greater than zero")
params = {'q': pattern, 'type': searchtype}
if limit is not None:
# fix for OWM 2.5 API bug!
# fix for OWM 3.0 API bug!
params['cnt'] = limit - 1
_, json_data = self.http_client.get_json(FIND_OBSERVATIONS_URI, params=params)
return observation.Observation.from_dict_of_lists(json_data)
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ What APIs can I access with PyOWM?

With PyOWM you can interact programmatically with the following OpenWeatherMap web APIs:

- **Weather API v2.5** + **OneCall API**, offering
- **Weather API v3.0** + **OneCall API**, offering
+ current weather data
+ weather forecasts
+ weather history
Expand Down
2 changes: 1 addition & 1 deletion sphinx/v3/global-pyowm-usage-examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ Most of PyOWM objects can be pretty-printed for a quick introspection:
```python
from pyowm.owm import OWM
owm = OWM('your-api-key')
print(owm) # <pyowm.weatherapi25.owm25.OWM25 - API key=*******i-key, subscription type=free, PyOWM version=3.0.0>
print(owm) # <pyowm.weatherapi30.owm25.OWM25 - API key=*******i-key, subscription type=free, PyOWM version=3.0.0>
```

2 changes: 1 addition & 1 deletion tests/integration/commons/test_cityidregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import unittest
from pyowm.commons.cityidregistry import CityIDRegistry
from pyowm.utils.geo import Point
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location


class TestCityIDRegistryReadsFS(unittest.TestCase):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest
import os
from pyowm import owm
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location


class IntegrationTestsGeocodingAPI(unittest.TestCase):
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/weatherapi25/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import pyowm.commons.exceptions
from pyowm import owm
from pyowm.weatherapi25.one_call import OneCall
from pyowm.weatherapi25.weather import Weather
from pyowm.weatherapi25.national_weather_alert import NationalWeatherAlert
from pyowm.weatherapi30.one_call import OneCall
from pyowm.weatherapi30.weather import Weather
from pyowm.weatherapi30.national_weather_alert import NationalWeatherAlert


class IntegrationTestsWebAPI25(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/proxy/test_integration_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pathlib
import unittest
from pyowm import OWM
from pyowm.weatherapi25.observation import Observation
from pyowm.weatherapi30.observation import Observation
from pyowm.utils import config


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/airpollutionapi30/test_airstatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from datetime import datetime
import pyowm.commons.exceptions
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location
from pyowm.airpollutionapi30.airstatus import AirStatus


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/airpollutionapi30/test_coindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from datetime import datetime
import pyowm.commons.exceptions
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location
from pyowm.airpollutionapi30.coindex import COIndex
from pyowm.utils.formatting import datetime_to_UNIXtime

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/airpollutionapi30/test_no2index.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import unittest
import json
from datetime import datetime
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location
from pyowm.commons.exceptions import ParseAPIResponseError
from pyowm.airpollutionapi30.no2index import NO2Index
from pyowm.utils.formatting import datetime_to_UNIXtime
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/airpollutionapi30/test_ozone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import json
from datetime import datetime
import pyowm.commons.exceptions
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location
from pyowm.airpollutionapi30.ozone import Ozone
from pyowm.utils.formatting import datetime_to_UNIXtime

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/airpollutionapi30/test_so2index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyowm.airpollutionapi30.so2index import SO2Index
from pyowm.commons.exceptions import ParseAPIResponseError
from pyowm.utils.formatting import datetime_to_UNIXtime
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location

SO2INDEX_JSON = '{"time":"2016-10-01T13:07:01Z","location":{"latitude":0,"longitude":9.2359},' \
'"data":[{"precision":-4.999999987376214e-07,"pressure":1000,"value":8.609262636127823e-08},' \
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/geocodingapi10/geocoding_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pyowm.config import DEFAULT_CONFIG
from pyowm.constants import GEOCODING_API_VERSION
from pyowm.geocodingapi10.geocoding_manager import GeocodingManager
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location


class TestGeocodingManager(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_owm.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from pyowm.stationsapi30.stations_manager import StationsManager
from pyowm.tiles.tile_manager import TileManager
from pyowm.uvindexapi30.uvindex_manager import UVIndexManager
from pyowm.weatherapi25.weather_manager import WeatherManager
from pyowm.weatherapi30.weather_manager import WeatherManager


class TestOWM(unittest.TestCase):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils/test_weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-

import unittest
from pyowm.weatherapi25.weather import Weather
from pyowm.weatherapi30.weather import Weather
from pyowm.utils import weather
from pyowm.weatherapi25.weathercoderegistry import WeatherCodeRegistry
from pyowm.weatherapi30.weathercoderegistry import WeatherCodeRegistry
from pyowm.commons.exceptions import NotFoundError


Expand Down
2 changes: 1 addition & 1 deletion tests/unit/uvindexapi30/test_uvindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from datetime import datetime
import pyowm.commons.exceptions
from pyowm.uvindexapi30 import uvindex
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi30.location import Location
from unittest.mock import patch


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import unittest
import json
from datetime import datetime
from pyowm.weatherapi25.location import Location
from pyowm.weatherapi25.weather import Weather
from pyowm.weatherapi25.forecast import Forecast
from pyowm.weatherapi30.location import Location
from pyowm.weatherapi30.weather import Weather
from pyowm.weatherapi30.forecast import Forecast
from pyowm.commons.exceptions import APIResponseError, ParseAPIResponseError
from tests.unit.weatherapi25.json_test_responses import (
from tests.unit.weatherapi30.json_test_responses import (
THREE_HOURS_FORECAST_JSON, FORECAST_NOT_FOUND_JSON,
INTERNAL_SERVER_ERROR_JSON, FORECAST_MALFORMED_JSON)

Expand Down
Loading

0 comments on commit dcef9c5

Please sign in to comment.