@@ -100,7 +100,7 @@ def __init__(self, currency, client, timeezone=None):
100100 "AggregatePrices" ,
101101 "AggregatePrices" ,
102102 "AggregatePrices" ,
103- "GetAnnuals" ,
103+ "AggregatePrices/ GetAnnuals" ,
104104 )
105105 self .API_URL = "https://dataportal-api.nordpoolgroup.com/api/%s"
106106 self .currency = currency
@@ -142,7 +142,7 @@ def _parse_json(self, data, areas=None, data_type=None):
142142 areas = list (areas )
143143
144144 # Ripped from Kipe's nordpool
145- elif data_type == self .DAILY :
145+ if data_type == self .DAILY :
146146 data_source = ("multiAreaDailyAggregates" , "averagePerArea" )
147147 elif data_type == self .WEEKLY :
148148 data_source = ("multiAreaWeeklyAggregates" , "averagePerArea" )
@@ -157,9 +157,12 @@ def _parse_json(self, data, areas=None, data_type=None):
157157 raise Exception (f"Invalid response from Nordpool API: { data } " )
158158
159159 # Update currency from data
160- currency = data ["currency" ]
160+ # currency it not avaiable in yearly... We just have to trust that the one
161+ # we set in the class is correct.
162+ currency = data .get ("currency" , self .currency )
161163
162164 # Ensure that the provided currency match the requested one
165+
163166 if currency != self .currency :
164167 raise CurrencyMismatch
165168
@@ -222,6 +225,9 @@ async def _fetch_json(self, data_type, end_date=None, areas=None):
222225 if not isinstance (end_date , date ) and not isinstance (end_date , datetime ):
223226 end_date = parse_dt (end_date )
224227
228+ if not isinstance (areas , list ) and areas is not None :
229+ areas = [i .strip () for i in areas .split ("," )]
230+
225231 kws = {
226232 "currency" : self .currency ,
227233 "market" : "DayAhead" ,
@@ -237,9 +243,9 @@ async def _fetch_json(self, data_type, end_date=None, areas=None):
237243
238244 # Add more exceptions as we find them. KeyError is raised when the api return
239245 # junk due to currency not being available in the data.
240- @backoff .on_exception (
241- backoff .expo , (aiohttp .ClientError , KeyError ), logger = _LOGGER , max_value = 20
242- )
246+ # @backoff.on_exception(
247+ # backoff.expo, (aiohttp.ClientError, KeyError), logger=_LOGGER, max_value=20
248+ # )
243249 async def fetch (self , data_type , end_date = None , areas = None ):
244250 """
245251 Fetch data from API.
@@ -268,12 +274,16 @@ async def fetch(self, data_type, end_date=None, areas=None):
268274 today = datetime .now ()
269275 tomorrow = datetime .now () + timedelta (days = 1 )
270276
271- jobs = [
272- self ._fetch_json (data_type , yesterday , areas ),
273- self ._fetch_json (data_type , today , areas ),
274- self ._fetch_json (data_type , tomorrow , areas ),
275- ]
276- print (jobs )
277+ if data_type == self .HOURLY :
278+ jobs = [
279+ self ._fetch_json (data_type , yesterday , areas ),
280+ self ._fetch_json (data_type , today , areas ),
281+ self ._fetch_json (data_type , tomorrow , areas ),
282+ ]
283+ else :
284+ # This is really not today but a year..
285+ # All except from hourly returns the raw values
286+ return await self ._fetch_json (data_type , today , areas )
277287
278288 res = await asyncio .gather (* jobs )
279289 raw = [
0 commit comments