scrapers/matemat/scrape.rb

36 lines
785 B
Ruby
Raw Normal View History

2020-04-04 04:11:14 +02:00
#!/usr/bin/env ruby
require 'open-uri'
require 'json'
require 'influxdb'
2020-04-04 04:23:40 +02:00
HOST = ARGV[0]
USER = ARGV[1]
PASSWORD = ARGV[2]
2020-04-04 04:11:14 +02:00
points = []
data = JSON.parse URI::open("https://#{HOST}/statistics.json", :http_basic_authentication => [USER, PASSWORD]).read()
2020-04-04 04:11:14 +02:00
points.push({
series: 'statistics',
values: data.map { |(n, i)| [n, i.to_i] },
2020-04-04 04:11:14 +02:00
})
data = JSON.parse URI::open("https://#{HOST}/summary.json", :http_basic_authentication => [USER, PASSWORD]).read()
2020-04-04 04:11:14 +02:00
data.each do |d|
points.push({
series: 'summary',
tags: {
name: d["name"],
},
values: {
2020-04-04 04:24:17 +02:00
price: d["price"].to_f,
2020-04-04 04:11:14 +02:00
value: d["value"],
2020-04-04 04:24:17 +02:00
volume: d["volume"].to_f,
2020-04-04 04:11:14 +02:00
}
})
end
db = InfluxDB::Client.new(url: "http://grafana.serv.zentralwerk.org:8086/matemat")
2020-04-04 04:11:14 +02:00
db.write_points(points, 'm')