gym_finder 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/lib/gym_finder/client.rb +5 -5
- data/lib/gym_finder/ocr.rb +9 -2
- data/lib/gym_finder/parser.rb +2 -2
- metadata +8 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: '006209e469d7d2a111ad24469d13845939bd6b0199fd4004ebb171bf5bbb61bc'
|
4
|
+
data.tar.gz: d82e44de799f56f9b9a1cfb27310757ddd0fbc74cc2204c5034dd09500e5aebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbea3bae1a1d995b73bb8779d8b58cd9634777c0d8543507f420ada7eed650b40742890da3260e3e53555e11a92f177de3b2430777a8559412a7f957830d218b
|
7
|
+
data.tar.gz: e2e939dae1e7568194edccf3e591f23e29b6c6f5fd076489828b8826c1072496d4c64848c1c1f46e85f2c118350a6b1146e2f89515dfa567622a6a256bcb08b4
|
data/lib/gym_finder/client.rb
CHANGED
@@ -17,7 +17,7 @@ module GymFinder
|
|
17
17
|
class Conn
|
18
18
|
attr_accessor :cookie
|
19
19
|
def initialize
|
20
|
-
@conn = EventMachine::HttpRequest.new('https://scr.cyc.org.tw/')
|
20
|
+
@conn = EventMachine::HttpRequest.new('https://scr.cyc.org.tw/', tls: { verify_peer: true })
|
21
21
|
@pending = 0
|
22
22
|
@processed = 0
|
23
23
|
end
|
@@ -73,7 +73,7 @@ module GymFinder
|
|
73
73
|
def initialize(
|
74
74
|
username: ENV['GYM_FINDER_USERNAME'],
|
75
75
|
password: ENV['GYM_FINDER_PASSWORD'],
|
76
|
-
retry_captcha:
|
76
|
+
retry_captcha: 30
|
77
77
|
)
|
78
78
|
@parser = Parser.new
|
79
79
|
@username = username
|
@@ -81,10 +81,10 @@ module GymFinder
|
|
81
81
|
@retry_captcha = retry_captcha
|
82
82
|
end
|
83
83
|
|
84
|
-
def fetch(
|
84
|
+
def fetch(**params)
|
85
85
|
captcha_error_count = 0
|
86
86
|
begin
|
87
|
-
_fetch(
|
87
|
+
_fetch(**params)
|
88
88
|
rescue CaptchaError => error
|
89
89
|
captcha_error_count += 1
|
90
90
|
raise error if captcha_error_count == @retry_captcha
|
@@ -117,7 +117,7 @@ module GymFinder
|
|
117
117
|
Captcha_text: captcha_text
|
118
118
|
}
|
119
119
|
) do |client|
|
120
|
-
raise CaptchaError
|
120
|
+
raise CaptchaError unless client.response.include?('修改會員資料')
|
121
121
|
GYMS.select(&gym_filter).each do |gym|
|
122
122
|
uri = URI(gym.reservation)
|
123
123
|
conn.get(path: uri.path) do |client|
|
data/lib/gym_finder/ocr.rb
CHANGED
@@ -10,8 +10,15 @@ module GymFinder
|
|
10
10
|
w.close
|
11
11
|
r2, w2 = IO.pipe
|
12
12
|
Open3.pipeline(
|
13
|
-
[
|
14
|
-
|
13
|
+
[
|
14
|
+
'convert', '-', '-channel', 'RGB', '-colorspace', 'GRAY',
|
15
|
+
'-depth', '1', '-negate',
|
16
|
+
'-define', 'connected-components:mean-color=true',
|
17
|
+
'-define', 'connected-components:area-threshold=2',
|
18
|
+
'-connected-components', '4',
|
19
|
+
'-crop', '60x17+4+4', '-'
|
20
|
+
],
|
21
|
+
['tesseract', 'stdin', 'stdout', '--psm', '8', '-c', 'tessedit_char_whitelist=0123456789', err: File.open('/dev/null', 'wb')],
|
15
22
|
in: r,
|
16
23
|
out: w2
|
17
24
|
)
|
data/lib/gym_finder/parser.rb
CHANGED
@@ -10,11 +10,11 @@ module GymFinder
|
|
10
10
|
class Parser
|
11
11
|
def parse_reservation(html)
|
12
12
|
doc = Nokogiri::HTML(html)
|
13
|
-
selector = '
|
13
|
+
selector = 'img[onclick*="net_booking"]'
|
14
14
|
Reservation.new.tap do |reservation|
|
15
15
|
reservation.available_courts = doc.css(selector).map do |node|
|
16
16
|
Reservation::Court.new.tap do |court|
|
17
|
-
court.name = node['
|
17
|
+
court.name = node['title']
|
18
18
|
court.pt = node['onclick'][/PT=(\d+)/, 1]
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gym_finder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jian Weihang
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email: tonytonyjan@gmail.com
|
85
85
|
executables:
|
86
86
|
- gym_finder
|
@@ -100,11 +100,11 @@ files:
|
|
100
100
|
- lib/gym_finder/post_processor.rb
|
101
101
|
- lib/gym_finder/reservation.rb
|
102
102
|
- lib/gym_finder/time_table.rb
|
103
|
-
homepage:
|
103
|
+
homepage:
|
104
104
|
licenses:
|
105
105
|
- MIT
|
106
106
|
metadata: {}
|
107
|
-
post_install_message:
|
107
|
+
post_install_message:
|
108
108
|
rdoc_options: []
|
109
109
|
require_paths:
|
110
110
|
- lib
|
@@ -119,9 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: '0'
|
121
121
|
requirements: []
|
122
|
-
|
123
|
-
|
124
|
-
signing_key:
|
122
|
+
rubygems_version: 3.1.2
|
123
|
+
signing_key:
|
125
124
|
specification_version: 4
|
126
125
|
summary: gym finder
|
127
126
|
test_files: []
|