Skip to content

Instantly share code, notes, and snippets.

@ckazu
Created March 6, 2014 05:23
Show Gist options
  • Save ckazu/9383096 to your computer and use it in GitHub Desktop.
Save ckazu/9383096 to your computer and use it in GitHub Desktop.
HRF の複合グラフを生成する
require 'json'
require 'nokogiri'
require 'open-uri'
service_name = 'kakin_daily'
section_name = 'count_uu_Android'
doc = Nokogiri::HTML(open 'https://hostname/add_complex')
graph_ids = doc.css('form select[name=path-add] option').
select {|graph| graph.content.match "/#{service_name}/#{section_name}/" }.
map {|graph| { 'path-data' => graph['value'] } }
options = {
stack: 1,
sort: 1,
service_name: service_name,
section_name: section_name,
graph_name: 'all'
} # don't merge graph_ids. duprecated key name
a = options.map {|key, value| %Q|-d "#{key}=#{value}"| }.join(' ')
b = graph_ids.map { |graph| %Q|-d "#{graph.keys.pop}=#{graph.values.pop}"| }.join(' ')
query = "#{a} #{b}"
result = `curl -X POST https://hostname/add_complex #{query}`
p JSON.parse result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment