28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/apt/kusa/cli.rb', line 28
def post
config = load_config
unless username = ENV["PIXELA_USER_NAME"] || config['username']
puts "Please set your username."
exit
end
unless token = ENV["PIXELA_USER_TOKEN"] || config['token']
puts "Please set your API token"
exit
end
summary = parse_and_summarize
client = Pixela::Client.new(username: username, token: token)
graph = client.graph(options[:graph])
if options[:create]
graph.create(
type: "int",
name: options[:graph_name],
unit: options[:graph_unit],
color: options[:graph_color],
timezone: options[:graph_tz]
)
end
summary.each do |date, count|
q = count.to_a.select{|h| [:install,:upgrade].include?(h[0])}.inject(0) {|s,h| s+=h[1]}
graph.pixel(Date.parse(date)).update(quantity: q)
end
end
|