Created
July 13, 2017 00:09
-
-
Save steveh/9da90c6976681422178849bf3cc887e3 to your computer and use it in GitHub Desktop.
PRS price to Influxdb
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
* * * * * /home/steve/power/price | /home/steve/power/write |
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
#!/usr/bin/env ruby | |
require "net/http" | |
require "uri" | |
require "csv" | |
poc = "CHANGEME" | |
url = "https://electricityinfo.co.nz/download/prices?search_form[run_types][]=A&search_form[market_types][]=E&search_form[nodes][]=#{poc}&search_form[tp_roll_back]=50&search_form[tp_roll_fwd]=50" | |
uri = URI(url) | |
res = Net::HTTP.get(uri) | |
CSV.parse(res, headers: true) do |row| | |
date = Date.strptime(row["Trading Date"], "%d/%m/%Y") | |
tp = row["Period"].to_i | |
time = date.to_time + (tp * 1800) | |
price = row["Price"].to_f / 10 | |
puts "price,gxp=%s,type=%s price=%s %s000000000\n" % [row["GIP/GXP"], "PRS", price.to_s, time.to_i] | |
end |
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
#!/bin/sh | |
HOST="localhost" | |
PORT="8086" | |
DATABASE="CHANGEME" | |
USERNAME="CHANGEME" | |
PASSWORD="CHANGEME" | |
curl -i -XPOST "http://$HOST:$PORT/write?db=$DATABASE&u=$USERNAME&p=$PASSWORD" --data-binary "@-" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment