winds-up-client 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/winds-up-client +9 -0
- data/lib/winds-up-client.rb +99 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cef1d2da6173822aaf711029a41f25628ff2f54460a755d080a5db3321095609
|
4
|
+
data.tar.gz: 0e962660ffc012b7351e8a44b4ec38d0db883f27a407a77ce357838a33ae0267
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4154869c1906230e6d66058efe0502f938ee51314b13eb204fefd48fd9902ebd63f2044b20719dd70964a04b19d703bb6be1a67c99a624310ebd83ed00256209
|
7
|
+
data.tar.gz: 6b813cb69e32c9cc7d03df04c19e45a53e397feeb6bf022e19ffc0c0f361973ebda2ba6767ab88206884026fac011cdbb1e98cef58d0c7d712d72dcdb4b1b196
|
data/bin/winds-up-client
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/bin/env ruby
|
2
|
+
require 'mechanize'
|
3
|
+
require 'date'
|
4
|
+
require 'json'
|
5
|
+
require 'terminal-table'
|
6
|
+
|
7
|
+
class WindsUpClient
|
8
|
+
|
9
|
+
def lpass what
|
10
|
+
`lpass show --#{what} winds-up.com`.chomp
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize options
|
14
|
+
@options = options
|
15
|
+
@options.merge!({username: lpass(:username), password: lpass(:password)}) if @options[:lpass]
|
16
|
+
end
|
17
|
+
|
18
|
+
def parse_series spot
|
19
|
+
Hash[[:actual, :expected].zip(spot.search("script").map do |script|
|
20
|
+
JSON.parse(script.children[0].text.match(/data: \[.*\]/)[0].gsub("data:", "").gsub(",}", "}").gsub(/(\w+):/, '"\1":'))
|
21
|
+
end)]
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse_spot spot
|
25
|
+
{
|
26
|
+
title: spot.search("a.title").map { |title| title.children.text },
|
27
|
+
wind: spot.search("div.infosvent2").map { |info| info.children[1].text }[0],
|
28
|
+
series: parse_series(spot)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def favorites_spots
|
33
|
+
agent = Mechanize.new
|
34
|
+
website = 'https://www.winds-up.com'
|
35
|
+
page = agent.get(website)
|
36
|
+
form = page.form('formu_login')
|
37
|
+
form["login_pseudo"] = @options[:username]
|
38
|
+
form["login_passwd"] = @options[:password]
|
39
|
+
agent.submit(form)
|
40
|
+
page = agent.get(website + '/index.php?p=favoris')
|
41
|
+
spots = page.search("div.mt3").reverse.map { |spot| parse_spot spot }
|
42
|
+
end
|
43
|
+
|
44
|
+
def series_handlers
|
45
|
+
{
|
46
|
+
actual: (-> (x) {"#{"=" * x["low"]}#{"-" * (x["high"] - x["low"])} #{(x["high"] + x["low"])/2}"}),
|
47
|
+
expected: (-> (x) {"#{ "*" * x["y"]} #{x["y"]} #{x["o"]}"})
|
48
|
+
}
|
49
|
+
end
|
50
|
+
|
51
|
+
def spot_row spot
|
52
|
+
title = [spot[:title], spot[:wind]]
|
53
|
+
i = 0
|
54
|
+
sampling = 2
|
55
|
+
rows = []
|
56
|
+
rows << title
|
57
|
+
series_handlers.each do |kind, handler|
|
58
|
+
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
|
60
|
+
i += 1
|
61
|
+
end
|
62
|
+
end
|
63
|
+
rows << title
|
64
|
+
end
|
65
|
+
|
66
|
+
def join_rows_ordered a, b
|
67
|
+
a.each_with_index.map do |a_row, i|
|
68
|
+
i < b.size ? a_row + b[i] : a_row
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def join_rows a, b
|
73
|
+
a.size > b.size ? join_rows_ordered(a, b) : join_rows_ordered(b, a)
|
74
|
+
end
|
75
|
+
|
76
|
+
def display_favorite_spots
|
77
|
+
spots = favorites_spots
|
78
|
+
previous_rows = []
|
79
|
+
spots.each_with_index do |spot, i|
|
80
|
+
if @options[:short]
|
81
|
+
puts "#{spot[:title]}: #{spot[:wind]}"
|
82
|
+
else
|
83
|
+
rows = spot_row spot
|
84
|
+
if i % 2 == 1
|
85
|
+
puts Terminal::Table.new :rows => join_rows(previous_rows, rows)
|
86
|
+
end
|
87
|
+
previous_rows = rows
|
88
|
+
end
|
89
|
+
end
|
90
|
+
puts Terminal::Table.new :rows => previous_rows if spots.size % 2 == 1 and !@options[:short]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
WindsUp.new(Trollop::options do
|
95
|
+
opt :short
|
96
|
+
opt :lpass
|
97
|
+
opt :user, "user", :type => :string
|
98
|
+
opt :password, "password", :type => :string
|
99
|
+
end).display_favorite_spots
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: winds-up-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Olivier Abdesselam
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-08-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: mechanize
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: date
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.1'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: terminal-table
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: trollop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
description: Allows to access winds-up.com on the CLI
|
84
|
+
email:
|
85
|
+
executables:
|
86
|
+
- winds-up-client
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- bin/winds-up-client
|
91
|
+
- lib/winds-up-client.rb
|
92
|
+
homepage: http://github.com/yazgoo/winds-up-client
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.7
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: client for winds-up.com
|
116
|
+
test_files: []
|