winds-up-client 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/winds-up-client +7 -4
- data/lib/winds-up-client.rb +51 -15
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c01dc1d45a5392f80552857adfb4f08ed4e814678005968cf74f3a7d995c9a2
|
4
|
+
data.tar.gz: 5f6897b47dc90b1c316c45cf954470d0e8a21ee69ad68cf253cb1a49279378d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e99af979e3c415a7589bb31aa7bec8e71f0bf6d930fa5c0bed84529d6a39d627ff69caa68318ed6bc8e9e956b6b8582d2447e082fa4e3d30e93757e72adddf22
|
7
|
+
data.tar.gz: 9736db772e497a813793f156d7793ef1136e3c101bd49cb1665c4347b390b56a5145bfbd1aab77b9019bd52ac5e6524b53cf70b2dd990a7ac049f4112c4748da
|
data/bin/winds-up-client
CHANGED
@@ -2,8 +2,11 @@
|
|
2
2
|
require 'winds-up-client'
|
3
3
|
require 'trollop'
|
4
4
|
WindsUpClient.new(Trollop::options do
|
5
|
-
opt :short
|
6
|
-
opt :lpass
|
7
|
-
opt :user, "user", :
|
8
|
-
opt :password, "password", :
|
5
|
+
opt :short, "short mode"
|
6
|
+
opt :lpass, "use lastpass-cli to retrieve credentials"
|
7
|
+
opt :user, "user", type: :string
|
8
|
+
opt :password, "password", type: :string
|
9
|
+
opt :sampling, "sampling factor for graphs", default: 2
|
10
|
+
opt :spot, "spot name", type: :string, default: nil
|
11
|
+
opt :nocolor, "no color"
|
9
12
|
end).display_favorite_spots
|
data/lib/winds-up-client.rb
CHANGED
@@ -2,7 +2,22 @@
|
|
2
2
|
require 'mechanize'
|
3
3
|
require 'date'
|
4
4
|
require 'json'
|
5
|
-
require '
|
5
|
+
require 'paint'
|
6
|
+
|
7
|
+
class TerminalTable
|
8
|
+
|
9
|
+
def initialize attributes
|
10
|
+
@rows = attributes[:rows]
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
return "" if @rows.size == 0
|
15
|
+
widths = @rows.reduce(@rows[0].size.times.to_a.map { 0 } ) { |memo, row| memo.each_with_index.map { |item, i| [row.size > i ? row[i].size : 0, item].max } }
|
16
|
+
@rows.map do |row|
|
17
|
+
row.each_with_index.map { |item, i| "#{item}#{" " * (widths[i] - item.size)}" }.join(" ")
|
18
|
+
end.join("\n")
|
19
|
+
end
|
20
|
+
end
|
6
21
|
|
7
22
|
class WindsUpClient
|
8
23
|
|
@@ -41,22 +56,41 @@ class WindsUpClient
|
|
41
56
|
spots = page.search("div.mt3").reverse.map { |spot| parse_spot spot }
|
42
57
|
end
|
43
58
|
|
59
|
+
def bar size, alternate, bg
|
60
|
+
if !@options[:nocolor]
|
61
|
+
Paint[(" " * size), nil, bg]
|
62
|
+
else
|
63
|
+
alternate * size
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def low size
|
68
|
+
bar size, "=", :blue
|
69
|
+
end
|
70
|
+
|
71
|
+
def high size
|
72
|
+
bar size, "-", :green
|
73
|
+
end
|
74
|
+
|
75
|
+
def expected size
|
76
|
+
bar size, "*", :yellow
|
77
|
+
end
|
78
|
+
|
44
79
|
def series_handlers
|
45
80
|
{
|
46
|
-
actual: (-> (x) {"#{
|
47
|
-
expected: (-> (x) {"#{
|
81
|
+
actual: (-> (x) {"#{low(x["low"])}#{high(x["high"] - x["low"])} #{(x["high"] + x["low"])/2}"}),
|
82
|
+
expected: (-> (x) {"#{ expected(x["y"])} #{x["y"]} #{x["o"]}"})
|
48
83
|
}
|
49
84
|
end
|
50
85
|
|
51
86
|
def spot_row spot
|
52
87
|
title = [spot[:title], spot[:wind]]
|
53
88
|
i = 0
|
54
|
-
sampling = 2
|
55
89
|
rows = []
|
56
90
|
rows << title
|
57
91
|
series_handlers.each do |kind, handler|
|
58
92
|
spot[:series][kind].each do |value|
|
59
|
-
rows << [Time.at(value["x"] / 1000).to_datetime.to_s.gsub(/\+.*/, ""), handler.call(value)] if i % sampling == 0
|
93
|
+
rows << [Time.at(value["x"] / 1000).to_datetime.to_s.gsub(/\+.*/, ""), handler.call(value)] if i % @options[:sampling] == 0
|
60
94
|
i += 1
|
61
95
|
end
|
62
96
|
end
|
@@ -77,16 +111,18 @@ class WindsUpClient
|
|
77
111
|
spots = favorites_spots
|
78
112
|
previous_rows = []
|
79
113
|
spots.each_with_index do |spot, i|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
114
|
+
if @options[:spot].nil? or spot[:title].downcase.include?(@options[:spot])
|
115
|
+
if @options[:short]
|
116
|
+
puts "#{spot[:title]}: #{spot[:wind]}"
|
117
|
+
else
|
118
|
+
rows = spot_row spot
|
119
|
+
if i % 2 == 1
|
120
|
+
puts TerminalTable.new :rows => join_rows(previous_rows, rows)
|
121
|
+
end
|
122
|
+
previous_rows = rows
|
123
|
+
end
|
124
|
+
end
|
89
125
|
end
|
90
|
-
puts
|
126
|
+
puts TerminalTable.new :rows => previous_rows if spots.size % 2 == 1 and !@options[:short]
|
91
127
|
end
|
92
128
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: winds-up-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Olivier Abdesselam
|
@@ -53,33 +53,33 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '2.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: trollop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1
|
61
|
+
version: '2.1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1
|
68
|
+
version: '2.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: paint
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '2.
|
75
|
+
version: '2.0'
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '2.
|
82
|
+
version: '2.0'
|
83
83
|
description: Allows to access winds-up.com on the CLI
|
84
84
|
email:
|
85
85
|
executables:
|