This repository was archived by the owner on Sep 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from jain-aayush1123/dest-weather
add destination weather api
- Loading branch information
Showing
15 changed files
with
785 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
==================== =============================================================================================================== === |
8 changes: 8 additions & 0 deletions
8
docs/source/here_location_services.config.dest_weather_config.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
8 changes: 8 additions & 0 deletions
8
docs/source/here_location_services.destination_weather_api.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.