kuport 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +3 -3
- data/bin/kuport +4 -1
- data/lib/kuport.rb +3 -2
- data/lib/kuport/helper.rb +34 -18
- data/lib/kuport/message.rb +1 -0
- data/lib/kuport/timetable.rb +5 -4
- data/lib/kuport/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99e516f62b18e1d41bf2018a86d343714e4802b2
|
4
|
+
data.tar.gz: db66947697cb358425e6858e6a02de0ee3edb8ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2f90af43af72870c3f7b6b1891c9c787e57d7e072ae2c7fdfbe1b1b299485835cd390c5c9829b10e14c3df2ccd40f2b23b3bf62a67b9ef6c4b347bc577ca000
|
7
|
+
data.tar.gz: b83aa1178067ee1506a2595f16e73434e69b2ba09eaf702c576ff010d2b96c54ea8fce0a83367a08d31bdbf5d0045b5520151b3ae0a52ad606891f6eab975605
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
```
|
7
|
+
```bash
|
8
8
|
$ gem install kuport
|
9
9
|
```
|
10
10
|
|
@@ -14,7 +14,7 @@ $ gem install kuport
|
|
14
14
|
|
15
15
|
端末でjsonを読むには`jid`がおすすめ。
|
16
16
|
|
17
|
-
```
|
17
|
+
```bash
|
18
18
|
$ go get github.com/simeji/jid/cmd/jid
|
19
19
|
$ cat sample.json | jid
|
20
20
|
```
|
@@ -24,7 +24,7 @@ $ cat sample.json | jid
|
|
24
24
|
一度ログインすればキャッシュが効くので、暫くは`--id`とパスワード入力は不要。
|
25
25
|
|
26
26
|
|
27
|
-
```
|
27
|
+
```bash
|
28
28
|
# 個人宛メッセージ取得
|
29
29
|
$ kuport --id jx91234 -m
|
30
30
|
|
data/bin/kuport
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require 'optparse'
|
3
3
|
require 'kuport'
|
4
4
|
|
5
|
+
using Kuport::ClassExtensions
|
6
|
+
|
5
7
|
# ruby2.3 <<~DOC
|
6
8
|
example_usage = <<USAGE
|
7
9
|
example usage
|
@@ -97,7 +99,8 @@ if opts[:id]
|
|
97
99
|
end
|
98
100
|
|
99
101
|
if opts[:download]
|
100
|
-
Kuport.quit('Need --output-file', 20) if
|
102
|
+
Kuport.quit('Need --output-file', 20) if opts[:download].url? && opts[:output_file].nil?
|
103
|
+
opts[:download] = STDIN.read if opts[:download] == '-'
|
101
104
|
kp.download(opts[:download], opts[:output_file])
|
102
105
|
end
|
103
106
|
|
data/lib/kuport.rb
CHANGED
@@ -12,6 +12,7 @@ require 'kuport/helper'
|
|
12
12
|
|
13
13
|
class Kuport
|
14
14
|
extend Kuport::Helper
|
15
|
+
using Kuport::ClassExtensions
|
15
16
|
|
16
17
|
class DownloadError < StandardError; end
|
17
18
|
|
@@ -91,7 +92,7 @@ class Kuport
|
|
91
92
|
|
92
93
|
def login(id)
|
93
94
|
return true if login_cookie
|
94
|
-
Kuport.quit('Please student id', 4) if
|
95
|
+
Kuport.quit('Please student id', 4) if id.blank?
|
95
96
|
|
96
97
|
3.times do
|
97
98
|
return true if login_passwd(id, Kuport.input_passwd)
|
@@ -131,7 +132,7 @@ class Kuport
|
|
131
132
|
# url_or_json is "http://....", {name:, path:}, or [{name:, path:}, ...]
|
132
133
|
# If url_or_json is URL, need file_path
|
133
134
|
def download(url_or_json, file_path=nil)
|
134
|
-
if
|
135
|
+
if url_or_json.url?
|
135
136
|
download_file(file_path, url_or_json)
|
136
137
|
return
|
137
138
|
end
|
data/lib/kuport/helper.rb
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
class Kuport
|
2
|
-
module Helper
|
3
|
-
def basename_noext(path)
|
4
|
-
File.basename(path, File.extname(path))
|
5
|
-
end
|
6
1
|
|
7
|
-
def br_to_return(element)
|
8
|
-
element.search('br').each{|br| br.replace("\n")}
|
9
|
-
end
|
10
2
|
|
3
|
+
class Kuport
|
4
|
+
module Helper
|
11
5
|
def to_abs_url(base, part)
|
12
6
|
uri = URI.parse(part)
|
13
7
|
uri = URI.join(base, uri) if URI::Generic === uri
|
@@ -22,14 +16,6 @@ class Kuport
|
|
22
16
|
Nokogiri::HTML.parse(page.content.toutf8)
|
23
17
|
end
|
24
18
|
|
25
|
-
def to_half_str(str)
|
26
|
-
NKF.nkf('-m0Z1 -w -W', str)
|
27
|
-
end
|
28
|
-
|
29
|
-
def url?(str)
|
30
|
-
str =~ /\A#{URI::regexp}\z/
|
31
|
-
end
|
32
|
-
|
33
19
|
def input_num(str)
|
34
20
|
print str
|
35
21
|
gets.to_i rescue nil
|
@@ -50,9 +36,39 @@ class Kuport
|
|
50
36
|
warn mes
|
51
37
|
exit ret
|
52
38
|
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassExtensions
|
42
|
+
refine Object do
|
43
|
+
def blank?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
refine String do
|
49
|
+
def to_half_str
|
50
|
+
NKF.nkf('-m0Z1 -w -W', self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def url?
|
54
|
+
self =~ /\A#{URI::regexp}\z/
|
55
|
+
end
|
56
|
+
|
57
|
+
def blank?
|
58
|
+
self.empty?
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
refine Nokogiri::XML::Node do
|
63
|
+
def br_to_return
|
64
|
+
self.search('br').each{|br| br.replace("\n")}
|
65
|
+
end
|
66
|
+
end
|
53
67
|
|
54
|
-
|
55
|
-
|
68
|
+
refine File do
|
69
|
+
def self.basename_noext(path)
|
70
|
+
File.basename(path, File.extname(path))
|
71
|
+
end
|
56
72
|
end
|
57
73
|
end
|
58
74
|
end
|
data/lib/kuport/message.rb
CHANGED
data/lib/kuport/timetable.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Kuport::Timetable
|
2
|
+
using Kuport::ClassExtensions
|
2
3
|
attr_reader :year, :dates, :table, :special
|
3
4
|
|
4
5
|
def initialize(doc)
|
@@ -15,7 +16,7 @@ class Kuport::Timetable
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def parse_dates(dates_doc)
|
18
|
-
|
19
|
+
dates_doc.br_to_return
|
19
20
|
tds = dates_doc.css('td')
|
20
21
|
@year = tds.shift.text
|
21
22
|
|
@@ -34,11 +35,11 @@ class Kuport::Timetable
|
|
34
35
|
tds.shift # 横枠破棄(1~7時限 集中講義等)
|
35
36
|
|
36
37
|
tds.zip(@table).each do |(td, day)| # 各曜日のn限
|
37
|
-
|
38
|
+
td.br_to_return
|
38
39
|
name,room,period = parse_class_text(td.text)
|
39
40
|
|
40
41
|
# 休講とか (kyuko)
|
41
|
-
status = td.css('img').map{|img|
|
42
|
+
status = td.css('img').map{|img| File.basename_noext(img['src'])}
|
42
43
|
day[1] << {name: name, room: room, period: period, status: status}
|
43
44
|
end
|
44
45
|
end
|
@@ -47,7 +48,7 @@ class Kuport::Timetable
|
|
47
48
|
def parse_class_text(text)
|
48
49
|
text.strip!
|
49
50
|
text = '' if text == '-'
|
50
|
-
text =
|
51
|
+
text = text.to_half_str
|
51
52
|
|
52
53
|
name,room,period = text.split("\n")
|
53
54
|
name.sub!(/\[(.+)\]/, '\1') if name
|
data/lib/kuport/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuport
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- u+
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.6.8
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Kuport scraping library and command
|