ruboty-rakuten_rental 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/lib/ruboty/handlers/rakuten_rental.rb +116 -0
- data/lib/ruboty/rakuten_rental.rb +14 -0
- data/lib/ruboty/rakuten_rental/version.rb +5 -0
- data/rakuten-rental.gemspec +25 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e6bc3e4ceae777075328062b8bedf7c48759219f
|
4
|
+
data.tar.gz: 091c3376a6ed96a8cc838e55936f52c2bd4ab5df
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d369ce76469893e7751aa75bbbc7da1a27e0de6c0a6ab21b1cc5757491304d03a05ee66f997989b4f87e44eccc0791a0ec51ec425fd4c13eaa18fb6cb3d10afc
|
7
|
+
data.tar.gz: 1c28638de28337c9ed5a02e3ae6edcad0a18688610b632239398de9146bfc5a15b0151f841c1a82547993e032eaf84d3e96698a0e9674a61105f81d4bfd3c8f5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 haccht
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Ruboty::Rakuten_rental
|
2
|
+
|
3
|
+
Ruboty handler to check whether there exists available items
|
4
|
+
in your Rakuten rental-list. http://rental.rakuten.jp
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'ruboty-rakuten_rental' :github => 'haccht/ruboty-rakuten_rental'
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```
|
15
|
+
> @ruboty list rakuten_rental
|
16
|
+
> @ruboty list rakuten_rental updated
|
17
|
+
```
|
18
|
+
|
19
|
+
## Env
|
20
|
+
|
21
|
+
Requires the Rakuten user account and password.
|
22
|
+
|
23
|
+
```
|
24
|
+
export RAKUTEN_USERNAME=
|
25
|
+
export RAKUTEN_PASSWORD=
|
26
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'stringio'
|
3
|
+
|
4
|
+
module Ruboty
|
5
|
+
module Handlers
|
6
|
+
class Rakuten_rental < Base
|
7
|
+
on(/list rakuten_rental(?<verbose> -v)?\z/,
|
8
|
+
name: 'list',
|
9
|
+
description: 'List Rakuten rental items.')
|
10
|
+
|
11
|
+
on(/list rakuten_rental updated(?<verbose> -v)?\z/,
|
12
|
+
name: 'list_updated',
|
13
|
+
description: 'List Rakuten rental items which became available.')
|
14
|
+
|
15
|
+
def initialize(*args)
|
16
|
+
super
|
17
|
+
@agent = Mechanize.new
|
18
|
+
end
|
19
|
+
|
20
|
+
def list(message)
|
21
|
+
items = []
|
22
|
+
list_items.each do |id, item|
|
23
|
+
items << item
|
24
|
+
cache[id] = item[:status]
|
25
|
+
end
|
26
|
+
|
27
|
+
text = StringIO.new
|
28
|
+
if items.empty?
|
29
|
+
text.puts "楽天レンタルに登録されているタイトルがないですね"
|
30
|
+
message.reply(text.string) if message[:verbose]
|
31
|
+
else
|
32
|
+
text.puts "楽天レンタルに次のタイトルが登録されていますね"
|
33
|
+
text.puts "http://rental.rakuten.jp/member/my_list/list"
|
34
|
+
text.puts
|
35
|
+
items.each do |item|
|
36
|
+
text.print "[#{item[:type]}] #{item[:title]} "
|
37
|
+
text.print "(#{item[:artist]}) " if item[:artist]
|
38
|
+
text.puts "- #{item[:price]} #{item[:status]}"
|
39
|
+
end
|
40
|
+
message.reply(text.string)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def list_updated(message)
|
45
|
+
items = []
|
46
|
+
list_items.each do |id, item|
|
47
|
+
last_status = cache[id].to_s.force_encoding('utf-8')
|
48
|
+
if item[:status] == "レンタル可能" && last_status != "レンタル可能"
|
49
|
+
items << item
|
50
|
+
end
|
51
|
+
|
52
|
+
cache[id] = item[:status]
|
53
|
+
end
|
54
|
+
|
55
|
+
text = StringIO.new
|
56
|
+
if items.empty?
|
57
|
+
text.puts "楽天レンタルで利用可能になったタイトルはないですね"
|
58
|
+
message.reply(text.string) if message[:verbose]
|
59
|
+
else
|
60
|
+
text.puts "楽天レンタルで次のタイトルが利用可能になったようですよ"
|
61
|
+
text.puts "http://rental.rakuten.jp/member/my_list/list"
|
62
|
+
text.puts
|
63
|
+
items.each do |item|
|
64
|
+
text.print "[#{item[:type]}] #{item[:title]} "
|
65
|
+
text.print "(#{item[:artist]}) " if item[:artist]
|
66
|
+
text.puts "- #{item[:price]}"
|
67
|
+
end
|
68
|
+
message.reply(text.string)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def list_items
|
73
|
+
items = {}
|
74
|
+
|
75
|
+
login do |page|
|
76
|
+
page.search('table[@class="myListTable"]/tr').each do |tr|
|
77
|
+
td = tr.search('td')
|
78
|
+
next if td.empty?
|
79
|
+
|
80
|
+
item = Hash.new
|
81
|
+
item[:type] = td[1].text.strip
|
82
|
+
item[:status] = td[2].text.strip
|
83
|
+
item[:title] = td[3].at_xpath('a').text.strip
|
84
|
+
item[:artist] = td[3].at_xpath('div').text.strip if td[3].at_xpath('div')
|
85
|
+
item[:price] = td[4].text.strip
|
86
|
+
|
87
|
+
id = td[0].at_xpath('input').get_attribute('name')
|
88
|
+
items[id] = item
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
items
|
93
|
+
end
|
94
|
+
|
95
|
+
def login
|
96
|
+
@agent.get(Ruboty::Rakuten_rental::MYLIST_URL) do |page|
|
97
|
+
page = page.forms.first.submit # redirect
|
98
|
+
page.form_with(name: "LoginForm") do |form|
|
99
|
+
form.field_with(name: 'u').value = Ruboty::Rakuten_rental::USERNAME
|
100
|
+
form.field_with(name: 'p').value = Ruboty::Rakuten_rental::PASSWORD
|
101
|
+
end.submit
|
102
|
+
end
|
103
|
+
|
104
|
+
@agent.get(Ruboty::Rakuten_rental::MYLIST_URL) do |page|
|
105
|
+
yield page
|
106
|
+
end
|
107
|
+
|
108
|
+
@agent.get(Ruboty::Rakuten_rental::LOGOUT_URL)
|
109
|
+
end
|
110
|
+
|
111
|
+
def cache
|
112
|
+
robot.brain.data[Ruboty::Rakuten_rental::NAMESPACE] ||= {}
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'ruboty'
|
2
|
+
require 'ruboty/handlers/rakuten_rental'
|
3
|
+
|
4
|
+
module Ruboty
|
5
|
+
module Rakuten_rental
|
6
|
+
NAMESPACE = 'rakuten_rental'
|
7
|
+
|
8
|
+
MYLIST_URL = 'https://rental.rakuten.jp/member/my_list/list'
|
9
|
+
LOGOUT_URL = 'https://rental.rakuten.jp/local/login/logout'
|
10
|
+
|
11
|
+
USERNAME = ENV['RAKUTEN_USERNAME']
|
12
|
+
PASSWORD = ENV['RAKUTEN_PASSWORD']
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
$LOAD_PATH << File.expand_path('../lib', __FILE__)
|
3
|
+
require 'ruboty/rakuten_rental/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'ruboty-rakuten_rental'
|
7
|
+
spec.version = Ruboty::Rakuten_rental::VERSION
|
8
|
+
spec.authors = ['haccht']
|
9
|
+
spec.email = ['haccht00@gmail.com']
|
10
|
+
spec.summary = "Ruboty handler to check whether there exists available items in your Rakuten rental-list."
|
11
|
+
spec.description = spec.summary
|
12
|
+
spec.homepage = 'https://github.com/haccht/ruboty-rakuten_rental'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_runtime_dependency 'ruboty'
|
21
|
+
spec.add_runtime_dependency 'mechanize'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'bundler'
|
24
|
+
spec.add_development_dependency 'rake'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-rakuten_rental
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- haccht
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mechanize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Ruboty handler to check whether there exists available items in your
|
70
|
+
Rakuten rental-list.
|
71
|
+
email:
|
72
|
+
- haccht00@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- lib/ruboty/handlers/rakuten_rental.rb
|
83
|
+
- lib/ruboty/rakuten_rental.rb
|
84
|
+
- lib/ruboty/rakuten_rental/version.rb
|
85
|
+
- rakuten-rental.gemspec
|
86
|
+
homepage: https://github.com/haccht/ruboty-rakuten_rental
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.4.8
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Ruboty handler to check whether there exists available items in your Rakuten
|
110
|
+
rental-list.
|
111
|
+
test_files: []
|