maimailog 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a4121923591a09603eb4baa4e7ff5ab597f385e
4
+ data.tar.gz: d5c20934a7c64e68a5b9b16e115699eb580ac05c
5
+ SHA512:
6
+ metadata.gz: 85f671cf4f35f70694c90b2fa9da802a2f02ccc53bbb4d467c3694da48e9c5a0537fc5f4c63fd98a6475699e1269f684a89875765bf80610652df2d174f8d9d4
7
+ data.tar.gz: b498e23e5718764fb851cba758eb1bd647865a5767be2f0c432d1aad9fc2eb5ae514ed2a025e3a0c9e6daf5c88b15086505d42ca8549535568d4da8aa890450a
@@ -0,0 +1,24 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ maimailog.iml
24
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in maimailog.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 utahta
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,49 @@
1
+ # Maimailog
2
+
3
+ maimai のプレイ履歴を取得する
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'maimailog'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install maimailog
18
+
19
+ ## Usage
20
+
21
+ ステータスを取得する
22
+
23
+ c = Maimailog::Crawler::Status.new
24
+ c.fetch(userid, passwd)
25
+
26
+ プレイ履歴を取得する
27
+
28
+ c = Maimailog::Crawler::History.new
29
+ c.login(userid, passwd)
30
+ page_num = 0
31
+ c.fetch(page_num) do |data|
32
+ p data
33
+ end
34
+
35
+ プレイ履歴を新しいものから順番に取得する
36
+
37
+ c = Maimailog::Crawler::History.new
38
+ c.login(userid, passwd)
39
+ c.fetch_all do |data|
40
+ p data
41
+ end
42
+
43
+ ## Contributing
44
+
45
+ 1. Fork it ( https://github.com/utahta/maimailog/fork )
46
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
47
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
48
+ 4. Push to the branch (`git push origin my-new-feature`)
49
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ require 'mechanize'
2
+ require 'date'
3
+ require 'maimailog/version'
4
+ require 'maimailog/data/status'
5
+ require 'maimailog/data/detail'
6
+ require 'maimailog/crawler/base'
7
+ require 'maimailog/crawler/status'
8
+ require 'maimailog/crawler/history'
@@ -0,0 +1,23 @@
1
+ module Maimailog
2
+ module Crawler
3
+
4
+ class Base
5
+ def initialize
6
+ @agent = Mechanize.new
7
+ end
8
+
9
+ ##
10
+ # maimainet にログインを試みる
11
+ # 成功したら home 画面ページが返る
12
+ def login(id, password)
13
+ page = @agent.get('https://maimai-net.com/maimai-mobile/login.html')
14
+ form = page.forms[0]
15
+ form.segaid = id
16
+ form.passwd = password
17
+ button = form.button_with(value: 'Sid Login')
18
+ @agent.submit(form, button)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,98 @@
1
+ module Maimailog
2
+ module Crawler
3
+
4
+ ##
5
+ # 詳細データを取得する
6
+ module Detail
7
+ private
8
+
9
+ # ページを詳細データに変換して返す
10
+ def convert_data(page)
11
+ data = Maimailog::Data::Detail.new
12
+ data.date = date(page)
13
+ data.difficulty = difficulty(page)
14
+ data.name = name(page)
15
+ data.judge = judge(page)
16
+ data.score = score(page)
17
+ data
18
+ end
19
+
20
+ def date(page)
21
+ str = page.search('//div[@class="accordion"]/h3').text[/[\d]{4}-[\d]{2}-[\d]{2} [\d]{2}:[\d]{2}/]
22
+ DateTime.strptime(str, '%Y-%m-%d %H:%M')
23
+ end
24
+
25
+ def difficulty(page)
26
+ page.search('//div[@class="accordion"]/ul/font')[1].text.strip
27
+ end
28
+
29
+ def name(page)
30
+ page.search('//div[@class="accordion"]/ul/li/table//td')[1].text.strip
31
+ end
32
+
33
+ def judge(page)
34
+ data = Maimailog::Data::Detail::Judge.new
35
+ data.perfect = page.search('//table[@class="detail"]//tr[1]//font')[1].text.to_i
36
+ data.great = page.search('//table[@class="detail"]//tr[2]//font')[1].text.to_i
37
+ data.good = page.search('//table[@class="detail"]//tr[3]//font')[1].text.to_i
38
+ data.miss = page.search('//table[@class="detail"]//tr[4]//font')[1].text.to_i
39
+ data
40
+ end
41
+
42
+ def score(page)
43
+ data = Maimailog::Data::Detail::Score.new
44
+ data.tap = page.search('//table[@class="detail"]//tr[6]//td[2]/div')[0].text.to_i
45
+ data.hold = page.search('//table[@class="detail"]//tr[7]//td[2]/div')[0].text.to_i
46
+ data.slide = page.search('//table[@class="detail"]//tr[8]//td[2]/div')[0].text.to_i
47
+ data.break = page.search('//table[@class="detail"]//tr[9]//td[2]/div')[0].text.to_i
48
+ data.tap_max = page.search('//table[@class="detail"]//tr[6]//td[3]//font')[0].text.to_i
49
+ data.hold_max = page.search('//table[@class="detail"]//tr[7]//td[3]//font')[0].text.to_i
50
+ data.slide_max = page.search('//table[@class="detail"]//tr[8]//td[3]//font')[0].text.to_i
51
+ data.break_max = page.search('//table[@class="detail"]//tr[9]//td[3]//font')[0].text.to_i
52
+ data
53
+ end
54
+ end
55
+
56
+ ##
57
+ # プレイ履歴を取得するクラス
58
+ class History < Base
59
+ include Detail
60
+ attr_writer :sleep_duration
61
+
62
+ # 取得間隔の初期値
63
+ DEFAULT_SLEEP_DURATION = 1
64
+
65
+ def initialize
66
+ super
67
+ @sleep_duration = DEFAULT_SLEEP_DURATION
68
+ end
69
+
70
+ # プレイ履歴ページからデータを取得して返す
71
+ # 事前に login を済ませておく必要がある
72
+ def fetch(page_num = 0)
73
+ page = @agent.page
74
+ raise 'require login.' if page.nil?
75
+
76
+ if page.uri.to_s[/home\.html/]
77
+ page = page.link_with(text: /[ ]+データ\z/).click
78
+ end
79
+ page = @agent.get("https://maimai-net.com/maimai-mobile/results.html?p=#{page_num}&#{page.uri.query[/sid=[\w]+/]}")
80
+
81
+ page.search('//div[@id="accordion"]/ul/li//a').each do |elm|
82
+ data = convert_data(@agent.get(elm[:href]))
83
+ sleep(@sleep_duration)
84
+ yield data
85
+ end
86
+ end
87
+
88
+ # プレイ履歴を最初から最後まで順番に取得していく
89
+ def fetch_all(&block)
90
+ 0.upto(9999) do |page_num|
91
+ data = fetch(page_num, &block)
92
+ break if data.size == 0
93
+ end
94
+ end
95
+ end
96
+
97
+ end
98
+ end
@@ -0,0 +1,32 @@
1
+ module Maimailog
2
+ module Crawler
3
+
4
+ ##
5
+ # ステータスを取得するクラス
6
+ class Status < Base
7
+
8
+ def fetch(id, password)
9
+ page = login(id, password)
10
+ Maimailog::Data::Status.new(name(page), rating(page), rating_max(page))
11
+ end
12
+
13
+ private
14
+
15
+ def name(page)
16
+ elm = page.search('//div[@class="status_name"]//font[@class="blue"]')
17
+ elm.empty? ? '' : elm[0].text.strip
18
+ end
19
+
20
+ def rating(page)
21
+ elm = page.search('//div[@class="status_data"]/font[@class="blue"]')
22
+ elm.empty? ? '' : elm[1].text.strip[/\d+\.\d+/].to_f
23
+ end
24
+
25
+ def rating_max(page)
26
+ elm = page.search('//div[@class="status_data"]/font[@class="blue"]')
27
+ elm.empty? ? '' : elm[1].text.strip[/ \d+\.\d+/].to_f
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,65 @@
1
+ module Maimailog
2
+ module Data
3
+
4
+ ##
5
+ # 詳細データ
6
+ class Detail
7
+ attr_accessor :name, :score, :date, :judge, :difficulty
8
+
9
+ ##
10
+ # ノーツ判定
11
+ class Judge
12
+ attr_accessor :great, :miss, :perfect, :good
13
+
14
+ def initialize
15
+ @perfect = 0
16
+ @great = 0
17
+ @good = 0
18
+ @miss = 0
19
+ end
20
+
21
+ def total
22
+ @perfect + @great + @good + @miss
23
+ end
24
+ end
25
+
26
+ ##
27
+ # スコア
28
+ class Score
29
+ attr_accessor :break, :slide, :tap, :hold, :break_max, :hold_max, :slide_max, :tap_max
30
+
31
+ def initialize
32
+ @tap = 0
33
+ @hold = 0
34
+ @slide = 0
35
+ @break = 0
36
+ @tap_max = 0
37
+ @hold_max = 0
38
+ @slide_max = 0
39
+ @break_max = 0
40
+ end
41
+
42
+ def total
43
+ @tap + @hold + @slide + @break
44
+ end
45
+
46
+ def total_max
47
+ @tap_max + @hold_max + @slide_max + @break_max
48
+ end
49
+
50
+ def rate
51
+ (total / total_max.to_f * 10000).floor / 100.0
52
+ end
53
+ end
54
+
55
+ def initialize
56
+ @date = nil
57
+ @difficulty = nil
58
+ @name = nil
59
+ @judge = Judge.new
60
+ @score = Score.new
61
+ end
62
+ end
63
+
64
+ end
65
+ end
@@ -0,0 +1,17 @@
1
+ module Maimailog
2
+ module Data
3
+
4
+ ##
5
+ # ステータスのデータクラス
6
+ class Status
7
+ attr_reader :name, :rating, :rating_max
8
+
9
+ def initialize(name, rating, rating_max)
10
+ @name = name
11
+ @rating = rating
12
+ @rating_max = rating_max
13
+ end
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module Maimailog
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'maimailog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "maimailog"
8
+ spec.version = Maimailog::VERSION
9
+ spec.authors = ["utahta"]
10
+ spec.email = ["labs.ninxit@gmail.com"]
11
+ spec.summary = %q{get the maimai play log}
12
+ spec.description = %q{get the maimai play log}
13
+ spec.homepage = "https://github.com/utahta/maimailog"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.6"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency 'mechanize', '~> 2.7.3'
25
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: maimailog
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - utahta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: mechanize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.7.3
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.7.3
55
+ description: get the maimai play log
56
+ email:
57
+ - labs.ninxit@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - lib/maimailog.rb
68
+ - lib/maimailog/crawler/base.rb
69
+ - lib/maimailog/crawler/history.rb
70
+ - lib/maimailog/crawler/status.rb
71
+ - lib/maimailog/data/detail.rb
72
+ - lib/maimailog/data/status.rb
73
+ - lib/maimailog/version.rb
74
+ - maimailog.gemspec
75
+ homepage: https://github.com/utahta/maimailog
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: get the maimai play log
99
+ test_files: []