Skip to content

Instantly share code, notes, and snippets.

@steveh
Created July 13, 2017 00:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveh/9da90c6976681422178849bf3cc887e3 to your computer and use it in GitHub Desktop.
Save steveh/9da90c6976681422178849bf3cc887e3 to your computer and use it in GitHub Desktop.
PRS price to Influxdb
* * * * * /home/steve/power/price | /home/steve/power/write
#!/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
#!/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