Skip to content
This repository has been archived by the owner on Sep 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from jain-aayush1123/dest-weather
Browse files Browse the repository at this point in the history
add destination weather api
  • Loading branch information
sackh committed Sep 6, 2021
2 parents e178ee9 + 78a3e4f commit bd4f6a3
Show file tree
Hide file tree
Showing 15 changed files with 785 additions and 8 deletions.
8 changes: 5 additions & 3 deletions docs/notebooks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
The example notebooks in this directory demonstrate various functionalities of `HERE Location Services`.

## Prerequisites

Before you run the Notebooks make sure you have:

- A HERE developer account, free and available under [HERE Developer Portal](https://developer.here.com)
- An [API key](https://developer.here.com/documentation/identity-access-management/dev_guide/topics/dev-apikey.html) from the [HERE Developer Portal](https://developer.here.com)


## Preparing for visualization

In order to run these Notebooks, you will need a few third-party dependencies. Please copy the following text to a file name anything you like, e.g. `requirements.txt`:
Expand All @@ -23,10 +24,11 @@ For visualization requirements please install [here-map-widget-for-jupyter](http

Follow installation steps from here: [here-map-widget-for-jupyter](https://github.com/heremaps/here-map-widget-for-jupyter#installation).


## Notebooks

- [Location Services](./location_services.ipynb) - Examples of various location services.
- [Restaurant Search](./isoline_routing_restaurant_search.ipynb) - Usecase of restarant search using isoline routing.
- [Routing](./routing.ipynb) - Examples of routing API.
- [Matrix Routing](./matrix_routing.ipynb) - Examples of Matrix routing API.
- [Matrix Routing](./matrix_routing.ipynb) - Examples of Matrix routing API.
- [Autosuggest](./autosuggest.ipynb) - Examples of Autosuggest API.
- [Destination Weather](./destination_weather.ipynb) - Examples of Destination Weather API.
105 changes: 105 additions & 0 deletions docs/notebooks/destination_weather.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"source": [
"import os\n",
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"import os\n",
"\n",
"from here_location_services import LS\n",
"from here_map_widget import Map, MarkerCluster, ObjectLayer\n",
"from here_location_services.config.dest_weather_config import DEST_WEATHER_PRODUCT\n",
"\n",
"\n",
"LS_API_KEY = os.environ.get(\"LS_API_KEY\")\n",
"ls = LS(api_key=LS_API_KEY)\n",
"\n",
"result1 = ls.get_dest_weather(\n",
" at=[19.1503, 72.8530],\n",
" products=[DEST_WEATHER_PRODUCT.observation]\n",
")\n",
"\n",
"results = []\n",
"m = Map(\n",
" api_key=LS_API_KEY,\n",
" center=[19.1621, 73.0008],\n",
" zoom=7,\n",
")\n",
"for observation in result1.places[0][\"observations\"]:\n",
" results.append(\n",
" dict(\n",
" lat=observation[\"place\"][\"location\"][\"lat\"],\n",
" lng=observation[\"place\"][\"location\"][\"lng\"],\n",
" data=observation[\"description\"] + \" \" + str(observation[\"temperature\"]) + \"C\",\n",
" )\n",
" )\n",
"\n",
"provider = MarkerCluster(data_points=results, show_bubble=True)\n",
"layer = ObjectLayer(provider=provider)\n",
"m.add_layer(layer)\n",
"m"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [
"from geojson import Point\n",
"from datetime import datetime\n",
"\n",
"result2 = ls.get_weather_alerts(\n",
" geometry=Point(coordinates=[15.256, 23.456]),\n",
" start_time=datetime.now(),\n",
" width=3000,\n",
" )\n",
"\n",
"print(result2)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"source": [],
"outputs": [],
"metadata": {}
}
],
"metadata": {
"orig_nbformat": 4,
"language_info": {
"name": "python",
"version": "3.9.6",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.9.6 64-bit"
},
"interpreter": {
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
96 changes: 96 additions & 0 deletions docs/source/dest_weather.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
Destination Weather
====================
`Destination Weather API <https://platform.here.com/services/details/hrn:here:service::olp-here:destination-weather-3/overview>`_ provides weather forecasts and reports on current weather conditions. It also provides information on severe weather alerts along a specified route or a single car location.

Example
-------

.. jupyter-execute::

import os
from here_location_services import LS
from here_map_widget import Map, MarkerCluster, ObjectLayer
from here_location_services.config.dest_weather_config import DEST_WEATHER_PRODUCT


LS_API_KEY = os.environ.get("LS_API_KEY")
ls = LS(api_key=LS_API_KEY)

result1 = ls.get_dest_weather(
at=[19.1503, 72.8530],
products=[DEST_WEATHER_PRODUCT.observation]
)

results = []
m = Map(
api_key=LS_API_KEY,
center=[19.1621, 73.0008],
zoom=7,
)
for observation in result1.places[0]["observations"]:
results.append(
dict(
lat=observation["place"]["location"]["lat"],
lng=observation["place"]["location"]["lng"],
data=observation["description"] + " " + str(observation["temperature"]) + "C",
)
)

provider = MarkerCluster(data_points=results, show_bubble=True)
layer = ObjectLayer(provider=provider)
m.add_layer(layer)
m

Attributes
----------

==================== =============================================================================================================== ===
Attribute Type Doc
==================== =============================================================================================================== ===
products list of :class:`DestWeatherProduct <here_location_services.config.dest_weather_config.DestWeatherProduct>` List of strings identifying the type of report to obtain.
at list optional A list of ``latitude`` and ``longitude`` specifying the area covered by the weather report.
query str optional Free text query. Examples: "125, Berliner, berlin", "Beacon, Boston"
zipcode str optional ZIP code of the location. This parameter is supported only for locations in the United States of America.
hourly_date :func:`datetime.datetime` optional Date for which hourly forecasts are to be retrieved.
one_observation bool optional Boolean, if set to true, the response only includes the closest location. Only available when the `product` parameter is set to `DEST_WEATHER_PRODUCT.observation`.
language str optional Defines the language used in the descriptions in the response.
units :class:`DestWeatherUnits <here_location_services.config.dest_weather_config.DestWeatherUnits>` optional Defines whether units or imperial units are used in the response.
==================== =============================================================================================================== ===

Getting Weather Alerts
----------------------
Can be used to get information on severe weather alerts along a specified route or a single car location.

.. jupyter-execute::

import os
from here_location_services import LS
from geojson import Point
from datetime import datetime

LS_API_KEY = os.environ.get("LS_API_KEY")
ls = LS(api_key=LS_API_KEY)
result = ls.get_weather_alerts(
geometry=Point(coordinates=[15.256, 23.456]),
start_time=datetime.now(),
width=3000,
)

print(result)


Attributes
----------

==================== =============================================================================================================== ===
Attribute Type Doc
==================== =============================================================================================================== ===
geometry Point or LineString or Polygon or MultiPolygon Point or LineString or Polygon or MultiPolygon defining the route or a single location
start_time :func:`datetime.datetime` Start time of the event
id str optional Unique weather alert id.
weather_severity :class:`WeatherSeverity <here_location_services.config.dest_weather_config.WeatherSeverity>` optional Defines the severity of the weather event
weather_type :class:`WeatherType <here_location_services.config.dest_weather_config.WeatherType>` optional Defines the type of the weather event
country str optional String for ISO-3166-1 2-letter country code.
end_time :func:`datetime.datetime` optional End time of the event. If not present, warning is valid until it is not removed from the feed by national weather institutes (valid until warning is present in the response)
width int optional int. default 50000
==================== =============================================================================================================== ===
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
here\_location\_services.config.dest\_weather\_config module
============================================================

.. automodule:: here_location_services.config.dest_weather_config
:members:
:undoc-members:
:show-inheritance:
:private-members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
here\_location\_services.destination\_weather\_api module
=========================================================

.. automodule:: here_location_services.destination_weather_api
:members:
:undoc-members:
:show-inheritance:
:private-members:
2 changes: 2 additions & 0 deletions docs/source/here_location_services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Submodules
here_location_services.config.base_config
here_location_services.config.autosuggest_config
here_location_services.config.isoline_routing_config
here_location_services.config.dest_weather_config
here_location_services.config.routing_config
here_location_services.config.matrix_routing_config
here_location_services.config.search_config.rst
Expand All @@ -33,3 +34,4 @@ Submodules
here_location_services.routing_api.rst
here_location_services.utils
here_location_services.platform
here_location_services.destination_weather_api.rst
6 changes: 6 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ A Python client for `HERE Location Services`_.
Routing <routing>
Matrix Routing <matrix_routing>

.. toctree::
:maxdepth: 1
:caption: Destination Weather

Destination Weather <dest_weather>

.. toctree::
:maxdepth: 1
:caption: Reference Guide
Expand Down
2 changes: 1 addition & 1 deletion here_location_services/config/autosuggest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SearchCircle:
defined by its center and radius(in meters).
"""

def __init__(self, lat: str, lng: str, radius: int):
def __init__(self, lat: float, lng: float, radius: int):
self.lat = lat
self.lng = lng
self.radius = radius
Expand Down
Loading

0 comments on commit bd4f6a3

Please sign in to comment.