winds-up-client 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c01dc1d45a5392f80552857adfb4f08ed4e814678005968cf74f3a7d995c9a2
4
- data.tar.gz: 5f6897b47dc90b1c316c45cf954470d0e8a21ee69ad68cf253cb1a49279378d1
3
+ metadata.gz: 604135a06e9e5d58e26990fcd1e174095f70f99755dfd6f874e499314b056086
4
+ data.tar.gz: 49ab8a197fc430bbf5523e507ae03c7c863f7dc0cf0fd6189706afd1e1eccce4
5
5
  SHA512:
6
- metadata.gz: e99af979e3c415a7589bb31aa7bec8e71f0bf6d930fa5c0bed84529d6a39d627ff69caa68318ed6bc8e9e956b6b8582d2447e082fa4e3d30e93757e72adddf22
7
- data.tar.gz: 9736db772e497a813793f156d7793ef1136e3c101bd49cb1665c4347b390b56a5145bfbd1aab77b9019bd52ac5e6524b53cf70b2dd990a7ac049f4112c4748da
6
+ metadata.gz: ad6ba01d16c9177fa45b75aec4fec7eeb2bb46b5bb4224348f250b5f65a18cf1fb1f3c5e49ab7ca2502500547080abc806964ee62c998743e1c09c612652b90f
7
+ data.tar.gz: fcfd8e0609c03cea95f73f0c217ccb83c98820dfba860595f5732387cba7e23f36aad87308fec458198197e3bf96694010bf10b8933fbfca55300c7c4f415d87
@@ -3,10 +3,12 @@ require 'winds-up-client'
3
3
  require 'trollop'
4
4
  WindsUpClient.new(Trollop::options do
5
5
  opt :short, "short mode"
6
+ opt :ultrashort, "ultra short mode"
6
7
  opt :lpass, "use lastpass-cli to retrieve credentials"
7
8
  opt :user, "user", type: :string
8
9
  opt :password, "password", type: :string
9
10
  opt :sampling, "sampling factor for graphs", default: 2
10
11
  opt :spot, "spot name", type: :string, default: nil
11
12
  opt :nocolor, "no color"
13
+ opt :cache, "cache result for a minute"
12
14
  end).display_favorite_spots
@@ -2,6 +2,7 @@
2
2
  require 'mechanize'
3
3
  require 'date'
4
4
  require 'json'
5
+ require 'yaml'
5
6
  require 'paint'
6
7
 
7
8
  class TerminalTable
@@ -76,15 +77,34 @@ class WindsUpClient
76
77
  bar size, "*", :yellow
77
78
  end
78
79
 
80
+ def to_arrows(cardinals)
81
+ {
82
+ se: "↖",
83
+ so: "↗",
84
+ no: "↘",
85
+ ne: "↙",
86
+ }.map { |name, value|
87
+ cardinals.sub!(name.to_s.upcase, value)
88
+ }
89
+ {
90
+ e: "←",
91
+ s: "↑",
92
+ o: "→",
93
+ n: "↓",
94
+ }.map { |name, value|
95
+ cardinals.sub!(name.to_s.upcase, value)
96
+ }
97
+ cardinals
98
+ end
79
99
  def series_handlers
80
100
  {
81
101
  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"]}"})
102
+ expected: (-> (x) {"#{ expected(x["y"])} #{x["y"]} #{to_arrows(x["o"])}"})
83
103
  }
84
104
  end
85
105
 
86
106
  def spot_row spot
87
- title = [spot[:title], spot[:wind]]
107
+ title = [spot[:title], to_arrows(spot[:wind])]
88
108
  i = 0
89
109
  rows = []
90
110
  rows << title
@@ -107,22 +127,43 @@ class WindsUpClient
107
127
  a.size > b.size ? join_rows_ordered(a, b) : join_rows_ordered(b, a)
108
128
  end
109
129
 
110
- def display_favorite_spots
130
+ def favorites_spots_text
131
+ result = ""
111
132
  spots = favorites_spots
112
133
  previous_rows = []
113
134
  spots.each_with_index do |spot, i|
114
135
  if @options[:spot].nil? or spot[:title].downcase.include?(@options[:spot])
115
136
  if @options[:short]
116
- puts "#{spot[:title]}: #{spot[:wind]}"
137
+ result += "#{spot[:title]}: #{to_arrows(spot[:wind])}\n"
138
+ elsif @options[:ultrashort]
139
+ result += "#{spot[:title][0]} #{to_arrows(spot[:wind]).sub(" nds", "")} "
117
140
  else
118
141
  rows = spot_row spot
119
142
  if i % 2 == 1
120
- puts TerminalTable.new :rows => join_rows(previous_rows, rows)
143
+ result += TerminalTable.new(:rows => join_rows(previous_rows, rows)).to_s
144
+ result += "\n"
121
145
  end
122
146
  previous_rows = rows
123
147
  end
124
148
  end
125
149
  end
126
- puts TerminalTable.new :rows => previous_rows if spots.size % 2 == 1 and !@options[:short]
150
+ result += TerminalTable.new(:rows => previous_rows).to_s if spots.size % 2 == 1 and !@options[:short]
151
+ result + "\n"
152
+ end
153
+
154
+ def favorites_spots_text_with_cache
155
+ path = "#{ENV['HOME']}/.local/share/winds-up-client.cache"
156
+ if Time.now - File.mtime(path) > 60
157
+ File.write(path, favorites_spots_text)
158
+ end
159
+ File.read(path)
160
+ end
161
+
162
+ def display_favorite_spots
163
+ if @options[:cache]
164
+ puts favorites_spots_text_with_cache
165
+ else
166
+ puts favorites_spots_text
167
+ end
127
168
  end
128
169
  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
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olivier Abdesselam