Skip to content

Commit

Permalink
docs: Update textforecast after rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroWave022 committed Oct 12, 2023
1 parent 5138208 commit 303e466
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 123 deletions.
20 changes: 20 additions & 0 deletions docs/textforecast/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,23 @@ Textforecast: API Reference
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: yr_weather.data.textforecast.TextForecasts
:members:
:undoc-members:

.. autoclass:: yr_weather.data.textforecast.TextForecastTime
:members:

.. autoclass:: yr_weather.data.textforecast.TextForecastLocations
:members:

Dataclasses
-----------
.. autoclass:: yr_weather.data.textforecast.ForecastLocation
:members:
:undoc-members:

.. autoclass:: yr_weather.data.textforecast.TextForecastArea
:members:
:undoc-members:
147 changes: 32 additions & 115 deletions docs/textforecast/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,137 +18,54 @@ The examples assume you have set up a :class:`Textforecast` client like so:

All of the next examples will use ``my_client`` as a reference to your client.

Getting text forecast for first location in API list
----------------------------------------------------
Getting text forecast for a location
------------------------------------

At the time of writing, text forecasts for land are only available in Norwegian.

.. code-block:: python
land_overview = text_client.get_forecasts("landoverview")
land_overview = my_client.get_forecasts("landoverview")
newest_forecast = land_overview["time"][0]["forecasttype"]
forecast_now = land_overview.now()
first_location = newest_forecast["location"][0]
# Location names are available at Textforecast.get_areas()
forecast_east = forecast_now.locations.get("Østlandet")
print(first_location)
print("The text forecast for Østlandet is:")
print(forecast_east.text)
# Example output:
# {
# 'name': 'Østlandet',
# 'id': '0503_0608',
# 'text': 'Skiftende eller sørvest bris, sørvest frisk bris på kysten. Oppholdsvær og noe sol.'
# }
# Vestlig bris, frisk bris utsatte steder, liten kuling på kysten. Nordøst i Innlandet fylke enkelte sludd- og regnbyger, ellers oppholdsvær og perioder med sol.
Getting available land areas
----------------------------
Getting available areas
-----------------------

.. code-block:: python
areas = my_client.get_areas("land")
print(areas)
areas = my_client.get_areas("land") # Can also get areas for "coast"
names = [area.name for area in areas]
names_string = ", ".join(names)
print(f"All available areas for textforecast are: {names_string}")
# Example output:
# {
# "area": [
# {
# "id": "0502",
# "areaDesc": "Agder",
# "polygon": "58.089167,8.215333 58.246167,8.525500 ..., ..."
# },
# {
# "id": "0502_0608",
# "areaDesc": "Telemark og Agder",
# "polygon": "59.672167,7.213167 59.653333,7.097667 ..., ..."
# },
# {
# "id": "0503",
# "areaDesc": "Østlandet",
# "polygon": "59.043667,10.653167 58.939167,10.904167 ..., ..."
# },
# {
# "id": "0503_0608",
# "areaDesc": "Østlandet og Telemark",
# "polygon": "58.930000,9.784667 58.956500,10.048167 ..., ..."
# },
# {
# "id": "0503_0608_0609_0610",
# "areaDesc": "Agder, Telemark, Østlandet",
# "polygon": "58.089167,8.215333 58.246167,8.525500 ..., ..."
# },
# {
# "id": "0504",
# "areaDesc": "Trøndelag",
# "polygon": "64.598333,9.853500 64.531333,9.714667 ..., ..."
# }, ...
# ]
# }
Getting coast forecasts in English
----------------------------------
# All available areas for textforecast are: Agder, Telemark og Agder, Østlandet, Østlandet og Telemark, ...
Getting other types of forecasts
--------------------------------

For available types of forecasts, see Textforecast's `documentation <https://api.met.no/weatherapi/textforecast/2.0/documentation>`__.

.. code-block:: python
forecasts = loc_cli.get_forecasts("coast_en")
coast_forecasts = my_client.get_forecasts("coast_no")
forecast_now = coast_forecasts.now()
# You can also get a forecast from the list manually
second_forecast = coast_forecasts.times[1]
print(forecasts)
print(f"Second forecast is valid from {second_forecast.from_time} and to {second_forecast.to_time}")
# Example output:
# {
# "xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance",
# "xsi:noNamespaceSchemaLocation": "https://schema.api.met.no/schemas/textforecast-0.3.xsd",
# "meta": {
# "licenseurl": "https://www.met.no/en/free-meteorological-data/Licensing-and-crediting"
# },
# "time": [
# {
# "from": "2023-01-28T18:00:00",
# "to": "2023-01-29T00:00:00",
# "forecasttype": [
# {
# "name": "normal",
# "location": [
# {
# "name": "Outer Skagerrak",
# "id": "0818",
# "text": "West occasionally force 6. Mainly dry and good. Significant wave height: 0,5-1,5 m."
# },
# {
# "name": "Inner Skagerrak",
# "id": "0817",
# "text": "West force 5. Dry. Good. Significant wave height: 0,5-1,5 m."
# }
# ]
# },
# {
# "name": "normal",
# "location": [
# {
# "name": "Inner Oslofjord",
# "id": "0816",
# "text": "West and southwest force 4. Cloudy or partly cloudy. Dry. Good. Significant wave height: 0,5 m or less."
# },
# {
# "name": "Swedish border - Lyngoer",
# "id": "51699",
# "text": "West and southwest occasionally force 5. Cloudy or partly cloudy. Dry. Good. Significant wave height: around 0,5 m."
# },
# {
# "name": "Lyngoer - Aana Sira",
# "id": "51676",
# "text": "West up to force 5. In west scattered rain showers, in east cloudy or partly cloudy, dry. Moderate in precipitation. Significant wave height: 0,5-1,5 m."
# },
# {
# "name": "Aana-Sira - Karmoey",
# "id": "9028_9029",
# "text": "West and northwest up to force 5, occasionally force 6 in southernmost part. Periods of rain showers. Moderate in precipitation. Significant wave height: 1,5-2,5 m."
# },
# {
# "name": "Karmoey - Stad",
# "id": "9030_9031_9032_9033_9034",
# "text": "Decreasing west force 4. Rain showers. Moderate in precipitation. Significant wave height: 2-4 m, highest in northernmost part,"
# }, ...
# ]
# }
# ]
# }, ...
# ]
# }
# Second forecast is valid from 2023-10-13T00:00:00 and to 2023-10-14T00:00:00
1 change: 0 additions & 1 deletion docs/textforecast/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ The :class:`Textforecast` class is used for interacting with the MET.no `Textfor

Examples <examples>
API <api>
Types <types>
7 changes: 0 additions & 7 deletions docs/textforecast/types.rst

This file was deleted.

0 comments on commit 303e466

Please sign in to comment.