This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Read data from website and import them into objects.
#2
Check this script out that Admin helped me out with a couple of days/weeks ago. It fetches the prices from Vattenfall API, maybe it will work for you with your price area?
In my Case I live in Sweden, pricearea SN3 (SE3).

Easiest practise would be to find a API with JSON output I beleive.

Code:
123456789101112131415161718192021222324252627282930313233343536373839404142
require('json') https = require 'ssl.https' date = os.date('%Y-%m-%d') url = 'https://www.vattenfall.se/api/price/spot/pricearea/' .. date .. '/' .. date .. '/SN3' status = ssl.https.request(url) data = json.decode(status) if type(data) ~= 'table' then   return end ts = data[ 1 ].TimeStampDay if type(ts) == 'string' then   ts = ts:split('-')   grp.checkupdate('5/5/28', {     year = tonumber(ts[1]),     month = tonumber(ts[2]),     day = tonumber(ts[3])   }) end min = math.huge max = -math.huge cnt = 0 sum = 0 for i, item in ipairs(data) do   price = item.Value   min = math.min(min, price)   max = math.max(max, price)   sum = sum + price   cnt = cnt + 1   grp.checkupdate('5/5/' .. i, price) end grp.checkupdate('5/5/25', sum / cnt) grp.checkupdate('5/5/26', max) grp.checkupdate('5/5/27', min)
Reply


Messages In This Thread
RE: Read data from website and import them into objects. - by sx3 - 17.11.2022, 06:42

Forum Jump: