55""" # noqa E501
66
77import time
8- from datetime import datetime
9- from typing import Any , Dict , List , Optional
8+ from datetime import date , datetime
9+ from typing import Any , Dict , List , Optional , Union
10+
11+ from geojson import Feature , FeatureCollection , LineString , MultiPolygon , Point , Polygon
1012
1113from here_location_services .platform .auth import Auth
1214
@@ -33,7 +35,7 @@ def get_dest_weather(
3335 at : Optional [List ] = None ,
3436 query : Optional [str ] = None ,
3537 zipcode : Optional [str ] = None ,
36- hourly_date : Optional [Any ] = None ,
38+ hourly_date : Optional [Union [ date , datetime ] ] = None ,
3739 one_observation : Optional [bool ] = None ,
3840 language : Optional [str ] = None ,
3941 units : Optional [str ] = None ,
@@ -49,7 +51,8 @@ def get_dest_weather(
4951 :param query: Free text query. Examples: "125, Berliner, berlin", "Beacon, Boston"
5052 :param zipcode: ZIP code of the location. This parameter is supported only for locations in
5153 the United States of America.
52- :param hourly_date: Date for which hourly forecasts are to be retrieved.
54+ :param hourly_date: Date for which hourly forecasts are to be retrieved. Can be either a `date` or
55+ `datetime` object
5356 :param one_observation: Boolean, if set to true, the response only includes the closest
5457 location. Only available when the `product` parameter is set to
5558 `DEST_WEATHER_PRODUCT.observation`.
@@ -71,7 +74,10 @@ def get_dest_weather(
7174 if zipcode :
7275 params ["zipCode" ] = zipcode
7376 if hourly_date :
74- params ["hourlyDate" ] = hourly_date .strftime ("%Y-%m-%dT%H:%M:%S" )
77+ if type (hourly_date ) is datetime .date :
78+ params ["hourlyDate" ] = hourly_date .strftime ("%Y-%m-%d" )
79+ else :
80+ params ["hourlyDate" ] = hourly_date .strftime ("%Y-%m-%dT%H:%M:%S" )
7581 if one_observation :
7682 params ["oneObservation" ] = "true" if one_observation else "false"
7783 if language :
@@ -87,9 +93,7 @@ def get_dest_weather(
8793
8894 def get_weather_alerts (
8995 self ,
90- feature_type : str ,
91- geometry_type : str ,
92- geometry_coordinates : List ,
96+ geometry : Union [Point , LineString , Polygon , MultiPolygon ],
9397 start_time : datetime ,
9498 id : Optional [str ] = None ,
9599 weather_severity : Optional [int ] = None ,
@@ -102,9 +106,8 @@ def get_weather_alerts(
102106
103107 See further information `Here Destination Weather API <https://developer.here.com/documentation/destination-weather/dev_guide/topics/overview.html>_`.
104108
105- :param feature_type: String to define feature type
106- :param geometry_type: Point or LineString or Polygon or MultiPolygon
107- :param geometry_coordinates: Array of coordinates corressponding to type provided
109+ :param geometry: Point or LineString or Polygon or MultiPolygon defining the route or
110+ a single location
108111 :param start_time: Start time of the event
109112 :param id: Unique weather alert id.
110113 :param weather_severity: Defines the severity of the weather event as defined
@@ -122,17 +125,6 @@ def get_weather_alerts(
122125
123126 path = "v3/alerts"
124127 url = f"{ self ._base_url } /{ path } "
125- data : Dict [str , Any ] = {
126- "type" : "FeatureCollection" ,
127- }
128- features : Dict [str , Any ] = {
129- "type" : feature_type ,
130- }
131-
132- if id :
133- features ["id" ] = id
134-
135- geometry : Dict [str , Any ] = {"type" : geometry_type , "coordinates" : geometry_coordinates }
136128
137129 properties : Dict [str , Any ] = {
138130 "width" : width ,
@@ -151,10 +143,19 @@ def get_weather_alerts(
151143 weather_warnings ["endTime" ] = time .mktime (end_time .timetuple ())
152144
153145 properties ["warnings" ] = [weather_warnings ]
154- features ["properties" ] = properties
155- features ["geometry" ] = geometry
156- data ["features" ] = [features ]
157- resp = self .post (url , data = data )
146+
147+ f = Feature (
148+ geometry = geometry ,
149+ properties = properties ,
150+ )
151+
152+ if id :
153+ f .id = id
154+
155+ feature_collection = FeatureCollection ([])
156+ feature_collection .features .append (f )
157+
158+ resp = self .post (url , data = feature_collection )
158159 if resp .status_code == 200 :
159160 return resp
160161 else :
0 commit comments