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

Commit bd4f6a3

Browse files
authored
Merge pull request #20 from jain-aayush1123/dest-weather
add destination weather api
2 parents e178ee9 + 78a3e4f commit bd4f6a3

15 files changed

+785
-8
lines changed

docs/notebooks/README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
The example notebooks in this directory demonstrate various functionalities of `HERE Location Services`.
44

55
## Prerequisites
6+
67
Before you run the Notebooks make sure you have:
8+
79
- A HERE developer account, free and available under [HERE Developer Portal](https://developer.here.com)
810
- 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)
911

10-
1112
## Preparing for visualization
1213

1314
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`:
@@ -23,10 +24,11 @@ For visualization requirements please install [here-map-widget-for-jupyter](http
2324

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

26-
2727
## Notebooks
2828

2929
- [Location Services](./location_services.ipynb) - Examples of various location services.
3030
- [Restaurant Search](./isoline_routing_restaurant_search.ipynb) - Usecase of restarant search using isoline routing.
3131
- [Routing](./routing.ipynb) - Examples of routing API.
32-
- [Matrix Routing](./matrix_routing.ipynb) - Examples of Matrix routing API.
32+
- [Matrix Routing](./matrix_routing.ipynb) - Examples of Matrix routing API.
33+
- [Autosuggest](./autosuggest.ipynb) - Examples of Autosuggest API.
34+
- [Destination Weather](./destination_weather.ipynb) - Examples of Destination Weather API.
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"source": [
7+
"import os\n",
8+
"os.environ[\"LS_API_KEY\"] = \"MY-API-KEY\" # replace your API key here."
9+
],
10+
"outputs": [],
11+
"metadata": {}
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"source": [
17+
"import os\n",
18+
"\n",
19+
"from here_location_services import LS\n",
20+
"from here_map_widget import Map, MarkerCluster, ObjectLayer\n",
21+
"from here_location_services.config.dest_weather_config import DEST_WEATHER_PRODUCT\n",
22+
"\n",
23+
"\n",
24+
"LS_API_KEY = os.environ.get(\"LS_API_KEY\")\n",
25+
"ls = LS(api_key=LS_API_KEY)\n",
26+
"\n",
27+
"result1 = ls.get_dest_weather(\n",
28+
" at=[19.1503, 72.8530],\n",
29+
" products=[DEST_WEATHER_PRODUCT.observation]\n",
30+
")\n",
31+
"\n",
32+
"results = []\n",
33+
"m = Map(\n",
34+
" api_key=LS_API_KEY,\n",
35+
" center=[19.1621, 73.0008],\n",
36+
" zoom=7,\n",
37+
")\n",
38+
"for observation in result1.places[0][\"observations\"]:\n",
39+
" results.append(\n",
40+
" dict(\n",
41+
" lat=observation[\"place\"][\"location\"][\"lat\"],\n",
42+
" lng=observation[\"place\"][\"location\"][\"lng\"],\n",
43+
" data=observation[\"description\"] + \" \" + str(observation[\"temperature\"]) + \"C\",\n",
44+
" )\n",
45+
" )\n",
46+
"\n",
47+
"provider = MarkerCluster(data_points=results, show_bubble=True)\n",
48+
"layer = ObjectLayer(provider=provider)\n",
49+
"m.add_layer(layer)\n",
50+
"m"
51+
],
52+
"outputs": [],
53+
"metadata": {}
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": null,
58+
"source": [
59+
"from geojson import Point\n",
60+
"from datetime import datetime\n",
61+
"\n",
62+
"result2 = ls.get_weather_alerts(\n",
63+
" geometry=Point(coordinates=[15.256, 23.456]),\n",
64+
" start_time=datetime.now(),\n",
65+
" width=3000,\n",
66+
" )\n",
67+
"\n",
68+
"print(result2)"
69+
],
70+
"outputs": [],
71+
"metadata": {}
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"source": [],
77+
"outputs": [],
78+
"metadata": {}
79+
}
80+
],
81+
"metadata": {
82+
"orig_nbformat": 4,
83+
"language_info": {
84+
"name": "python",
85+
"version": "3.9.6",
86+
"mimetype": "text/x-python",
87+
"codemirror_mode": {
88+
"name": "ipython",
89+
"version": 3
90+
},
91+
"pygments_lexer": "ipython3",
92+
"nbconvert_exporter": "python",
93+
"file_extension": ".py"
94+
},
95+
"kernelspec": {
96+
"name": "python3",
97+
"display_name": "Python 3.9.6 64-bit"
98+
},
99+
"interpreter": {
100+
"hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49"
101+
}
102+
},
103+
"nbformat": 4,
104+
"nbformat_minor": 2
105+
}

docs/source/dest_weather.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
Destination Weather
2+
====================
3+
`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.
4+
5+
Example
6+
-------
7+
8+
.. jupyter-execute::
9+
10+
import os
11+
from here_location_services import LS
12+
from here_map_widget import Map, MarkerCluster, ObjectLayer
13+
from here_location_services.config.dest_weather_config import DEST_WEATHER_PRODUCT
14+
15+
16+
LS_API_KEY = os.environ.get("LS_API_KEY")
17+
ls = LS(api_key=LS_API_KEY)
18+
19+
result1 = ls.get_dest_weather(
20+
at=[19.1503, 72.8530],
21+
products=[DEST_WEATHER_PRODUCT.observation]
22+
)
23+
24+
results = []
25+
m = Map(
26+
api_key=LS_API_KEY,
27+
center=[19.1621, 73.0008],
28+
zoom=7,
29+
)
30+
for observation in result1.places[0]["observations"]:
31+
results.append(
32+
dict(
33+
lat=observation["place"]["location"]["lat"],
34+
lng=observation["place"]["location"]["lng"],
35+
data=observation["description"] + " " + str(observation["temperature"]) + "C",
36+
)
37+
)
38+
39+
provider = MarkerCluster(data_points=results, show_bubble=True)
40+
layer = ObjectLayer(provider=provider)
41+
m.add_layer(layer)
42+
m
43+
44+
Attributes
45+
----------
46+
47+
==================== =============================================================================================================== ===
48+
Attribute Type Doc
49+
==================== =============================================================================================================== ===
50+
products list of :class:`DestWeatherProduct <here_location_services.config.dest_weather_config.DestWeatherProduct>` List of strings identifying the type of report to obtain.
51+
at list optional A list of ``latitude`` and ``longitude`` specifying the area covered by the weather report.
52+
query str optional Free text query. Examples: "125, Berliner, berlin", "Beacon, Boston"
53+
zipcode str optional ZIP code of the location. This parameter is supported only for locations in the United States of America.
54+
hourly_date :func:`datetime.datetime` optional Date for which hourly forecasts are to be retrieved.
55+
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`.
56+
language str optional Defines the language used in the descriptions in the response.
57+
units :class:`DestWeatherUnits <here_location_services.config.dest_weather_config.DestWeatherUnits>` optional Defines whether units or imperial units are used in the response.
58+
==================== =============================================================================================================== ===
59+
60+
Getting Weather Alerts
61+
----------------------
62+
Can be used to get information on severe weather alerts along a specified route or a single car location.
63+
64+
.. jupyter-execute::
65+
66+
import os
67+
from here_location_services import LS
68+
from geojson import Point
69+
from datetime import datetime
70+
71+
LS_API_KEY = os.environ.get("LS_API_KEY")
72+
ls = LS(api_key=LS_API_KEY)
73+
result = ls.get_weather_alerts(
74+
geometry=Point(coordinates=[15.256, 23.456]),
75+
start_time=datetime.now(),
76+
width=3000,
77+
)
78+
79+
print(result)
80+
81+
82+
Attributes
83+
----------
84+
85+
==================== =============================================================================================================== ===
86+
Attribute Type Doc
87+
==================== =============================================================================================================== ===
88+
geometry Point or LineString or Polygon or MultiPolygon Point or LineString or Polygon or MultiPolygon defining the route or a single location
89+
start_time :func:`datetime.datetime` Start time of the event
90+
id str optional Unique weather alert id.
91+
weather_severity :class:`WeatherSeverity <here_location_services.config.dest_weather_config.WeatherSeverity>` optional Defines the severity of the weather event
92+
weather_type :class:`WeatherType <here_location_services.config.dest_weather_config.WeatherType>` optional Defines the type of the weather event
93+
country str optional String for ISO-3166-1 2-letter country code.
94+
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)
95+
width int optional int. default 50000
96+
==================== =============================================================================================================== ===
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
here\_location\_services.config.dest\_weather\_config module
2+
============================================================
3+
4+
.. automodule:: here_location_services.config.dest_weather_config
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:private-members:
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
here\_location\_services.destination\_weather\_api module
2+
=========================================================
3+
4+
.. automodule:: here_location_services.destination_weather_api
5+
:members:
6+
:undoc-members:
7+
:show-inheritance:
8+
:private-members:

docs/source/here_location_services.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Submodules
1919
here_location_services.config.base_config
2020
here_location_services.config.autosuggest_config
2121
here_location_services.config.isoline_routing_config
22+
here_location_services.config.dest_weather_config
2223
here_location_services.config.routing_config
2324
here_location_services.config.matrix_routing_config
2425
here_location_services.config.search_config.rst
@@ -33,3 +34,4 @@ Submodules
3334
here_location_services.routing_api.rst
3435
here_location_services.utils
3536
here_location_services.platform
37+
here_location_services.destination_weather_api.rst

docs/source/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ A Python client for `HERE Location Services`_.
3636
Routing <routing>
3737
Matrix Routing <matrix_routing>
3838

39+
.. toctree::
40+
:maxdepth: 1
41+
:caption: Destination Weather
42+
43+
Destination Weather <dest_weather>
44+
3945
.. toctree::
4046
:maxdepth: 1
4147
:caption: Reference Guide

here_location_services/config/autosuggest_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SearchCircle:
1313
defined by its center and radius(in meters).
1414
"""
1515

16-
def __init__(self, lat: str, lng: str, radius: int):
16+
def __init__(self, lat: float, lng: float, radius: int):
1717
self.lat = lat
1818
self.lng = lng
1919
self.radius = radius

0 commit comments

Comments
 (0)