kipe / nordpool

Python library for fetching Nord Pool spot prices.
MIT License
96 stars 37 forks source link

Page lookup helpers #20

Closed jschlyter closed 3 years ago

jschlyter commented 3 years ago

First step to resolve #17 is to find the correct page given area and data type.

Example

from nordpool import elspot

spot = elspot.Prices(currency="SEK")
page = spot.get_page(country="SE", data_type=elspot.NordpoolDataType.HOURLY)
data = spot.fetch(page, end_date=date.today(), areas=["SE1", "SE2", "SE3", "SE4"])
Hellowlol commented 3 years ago

Why +1 why set the correct page index in the dict?

jschlyter commented 3 years ago

Why +1 why set the correct page index in the dict?

The hourly/daily/weekly/monthly/yearly pages has an offset from the base page of 1…5. In order to maintain backward compability I choosed to calculate it backwards. I agree it is a bit confusing, so I've changed to more obvious logic in c012f3875f1157fa2b4d55998b7abbb9fef316af.

kipe commented 3 years ago

I'll see if this could be done without changes to the API, without too much spaghetti. It would be a lot nicer way to implement it. Although we'll see how long this API even stays, Nordpool has been hinting on making an official API for non-commercial use.

jschlyter commented 3 years ago

I'll see if this could be done without changes to the API, without too much spaghetti. It would be a lot nicer way to implement it. Although we'll see how long this API even stays, Nordpool has been hinting on making an official API for non-commercial use.

I'd prefer if the API would not change, but with this code it is at least possible to adopt. Happy to see it solved without the extra call to get_page().

kipe commented 3 years ago

Closing for now, as it seems like Nordpool has fixed the issue in their end.