rerave 0.1.0
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +71 -0
- data/Rakefile +1 -0
- data/bin/rerave +5 -0
- data/lib/rerave.rb +5 -0
- data/lib/rerave/archive.rb +6 -0
- data/lib/rerave/cli.rb +142 -0
- data/lib/rerave/version.rb +3 -0
- data/rerave.gemspec +26 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c1377bb8049079ed867ab34a5578e4888dba51c1
|
4
|
+
data.tar.gz: 17c7ed7fe135bd4ee2e0a7fab76ed0a58f824469
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b35b8cbc413103ed0f5216add98cdcf41d7a94cc1b758e9f40682f5d260b6c7ac73be2cd8c1f2f4e4c91829edd14fff67a990a7b7bea09f9fffa318e6152525
|
7
|
+
data.tar.gz: 40580e7c78e34395d119cbdccfd96e27ffa39db101995ab13a87018acd3f9481f44466a332b1ff16391f5870092b142fda18f99a54928a8c7e736da7385b6d55
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Steve Klabnik
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# Rerave
|
2
|
+
|
3
|
+
A gem to calculate score statistics for [ReRave](http://www.rerave.com).
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rerave'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rerave
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
As of right now, the gem will calculate which song a give user should play
|
22
|
+
next, based on how far away they are from the highest score.
|
23
|
+
|
24
|
+
Example:
|
25
|
+
|
26
|
+
```bash
|
27
|
+
$ rerave next steveklabnik
|
28
|
+
Scraping top scores..........done.
|
29
|
+
Scraping scores for steveklabnik
|
30
|
+
............................................................................................done.
|
31
|
+
Here are the songs steveklabnik should play next:
|
32
|
+
#1: Your Own Destiny: master (63829)
|
33
|
+
#2: Got The Rhythm: master (30314)
|
34
|
+
#3: Delirium: master (29185)
|
35
|
+
#4: Hookie Mammoth: master (24065)
|
36
|
+
#5: Stream: master (19490)
|
37
|
+
#6: Once Again: master (12520)
|
38
|
+
#7: Tricky Disco 2k10: master (11458)
|
39
|
+
#8: Insomnia: master (11431)
|
40
|
+
#9: Dam Dadi Doo: master (10732)
|
41
|
+
#10: Rock That Style: master (10061)
|
42
|
+
#11: Rome0 & Juli8: master (9904)
|
43
|
+
#12: Ignition Starts: master (9286)
|
44
|
+
#13: Popcorn: master (9124)
|
45
|
+
#14: Contrast: master (9120)
|
46
|
+
#15: Subzero: master (8964)
|
47
|
+
#16: Bits & Bytes: master (8669)
|
48
|
+
#17: Rock N' Russia: master (8055)
|
49
|
+
#18: The Pure And The Tainted: master (7732)
|
50
|
+
#19: London Bridge: master (7597)
|
51
|
+
#20: Who R You: master (6865)
|
52
|
+
$
|
53
|
+
```
|
54
|
+
|
55
|
+
As of right now, it will only calculate scores for iOS.
|
56
|
+
|
57
|
+
It caches scores locally as to not hammer ReRave's servers over and over.
|
58
|
+
|
59
|
+
To clear the cache:
|
60
|
+
|
61
|
+
```bash
|
62
|
+
$ rerave clear
|
63
|
+
```
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
1. Fork it
|
68
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
69
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
70
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
71
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/rerave
ADDED
data/lib/rerave.rb
ADDED
data/lib/rerave/cli.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'mechanize'
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
module Rerave
|
7
|
+
class CLI < Thor
|
8
|
+
|
9
|
+
desc "clear", "Clear out the cached scores."
|
10
|
+
def clear
|
11
|
+
dir = "#{Dir.home}/.rerave/"
|
12
|
+
FileUtils.rm_rf(dir)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "top", "Create local archive of top scores"
|
16
|
+
def top
|
17
|
+
top_scores = {}
|
18
|
+
dir = "#{Dir.home}/.rerave/"
|
19
|
+
|
20
|
+
FileUtils.mkdir_p(dir)
|
21
|
+
|
22
|
+
top_file = "#{dir}/top_scores.dump"
|
23
|
+
unless Pathname.new(top_file).exist?
|
24
|
+
top_scores = scrape_top_scores
|
25
|
+
|
26
|
+
File.open(top_file,'wb') do |f|
|
27
|
+
f.write Marshal.dump(top_scores)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
desc "scores [username]", "Create local archive of your scores"
|
33
|
+
def scores(username)
|
34
|
+
user_scores = {}
|
35
|
+
dir = "#{Dir.home}/.rerave/"
|
36
|
+
|
37
|
+
FileUtils.mkdir_p(dir)
|
38
|
+
|
39
|
+
user_file = "#{dir}/#{username}_scores.dump"
|
40
|
+
unless Pathname.new(user_file).exist?
|
41
|
+
user_scores = scrape_scores(username)
|
42
|
+
|
43
|
+
File.open(user_file,'wb') do |f|
|
44
|
+
f.write Marshal.dump(user_scores)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
desc "next [username]", "Calculate top songs to play next"
|
50
|
+
def next(username)
|
51
|
+
dir = "#{Dir.home}/.rerave/"
|
52
|
+
|
53
|
+
top
|
54
|
+
top_file = "#{dir}/top_scores.dump"
|
55
|
+
top_scores = Marshal.load (File.binread(top_file))
|
56
|
+
|
57
|
+
scores(username)
|
58
|
+
user_file = "#{dir}/#{username}_scores.dump"
|
59
|
+
user_scores = Marshal.load (File.binread(user_file))
|
60
|
+
|
61
|
+
diff = {}
|
62
|
+
|
63
|
+
top_scores.each do |name, scores|
|
64
|
+
user_difficulties = user_scores[name]
|
65
|
+
scores.each do |difficulty, score|
|
66
|
+
diff["#{name}: #{difficulty}"] = score - user_difficulties[difficulty]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "Here are the songs #{username} should play next:"
|
71
|
+
|
72
|
+
diff.sort_by{|k, v| v }.reverse.take(20).each_with_index do |(name, difference), i|
|
73
|
+
puts "##{i + 1}: #{name} (#{difference})"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def scrape_top_scores
|
80
|
+
print "Scraping top scores"
|
81
|
+
a = Mechanize.new
|
82
|
+
scores = {}
|
83
|
+
|
84
|
+
(1..10).each do |i|
|
85
|
+
print "."
|
86
|
+
a.get("http://www.rerave.com/music/page/#{i}/") do |music_page|
|
87
|
+
music_page.links_with(text: "Top iOS Scores").each do |score_link|
|
88
|
+
easy, hard, master = nil, nil, nil
|
89
|
+
|
90
|
+
score_page = a.click(score_link)
|
91
|
+
name = score_page.search("#leaderboard_info h1").text
|
92
|
+
|
93
|
+
easy_page = a.click(score_page.link_with(text: "Easy"))
|
94
|
+
|
95
|
+
easy_page.search(".ranking_row").each do |row|
|
96
|
+
easy = row.search(".score_easy + .score_easy").text.gsub(/\D/, "").to_i
|
97
|
+
end
|
98
|
+
|
99
|
+
hard_page = a.click(score_page.link_with(text: "Hard"))
|
100
|
+
hard_page.search(".ranking_row").each do |row|
|
101
|
+
hard = row.search(".score_hard + .score_hard").text.gsub(/\D/, "").to_i
|
102
|
+
end
|
103
|
+
|
104
|
+
master_page = a.click(score_page.link_with(text: "Master"))
|
105
|
+
master_page.search(".ranking_row").each do |row|
|
106
|
+
master = row.search(".score_master + .score_master").text.gsub(/\D/, "").to_i
|
107
|
+
end
|
108
|
+
|
109
|
+
scores[name] = {"easy" => easy, "hard" => hard, "master" => master}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
puts "done."
|
115
|
+
|
116
|
+
scores
|
117
|
+
end
|
118
|
+
|
119
|
+
def scrape_scores(username)
|
120
|
+
puts "Scraping scores for #{username}"
|
121
|
+
a = Mechanize.new
|
122
|
+
scores = {}
|
123
|
+
|
124
|
+
a.get("http://www.rerave.com/rankings/?rankings_search=#{username}&platform=iOS") do |my_page|
|
125
|
+
my_page.search(".ranking_row .ranking_row").each do |row|
|
126
|
+
print "."
|
127
|
+
easy = row.search("span.score_easy.score_span").text.gsub(/\D/, "").to_i
|
128
|
+
hard = row.search("span.score_hard.score_span").text.gsub(/\D/, "").to_i
|
129
|
+
master = row.search("span.score_master.score_span").text.gsub(/\D/, "").to_i
|
130
|
+
|
131
|
+
name = row.search(".ranking_data h1").text
|
132
|
+
|
133
|
+
scores[name] = {"easy" => easy, "hard" => hard, "master" => master}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
puts "done."
|
138
|
+
|
139
|
+
scores
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
data/rerave.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rerave/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rerave"
|
8
|
+
spec.version = Rerave::VERSION
|
9
|
+
spec.authors = ["Steve Klabnik"]
|
10
|
+
spec.email = ["steve@steveklabnik.com"]
|
11
|
+
spec.description = %q{Calculate score statistics for ReRave.}
|
12
|
+
spec.summary = %q{Calculate score statistics for ReRave.}
|
13
|
+
spec.homepage = "http://github.com/steveklabnik/rerave"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_dependency "thor"
|
22
|
+
spec.add_dependency "mechanize"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rerave
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Klabnik
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
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: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
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: Calculate score statistics for ReRave.
|
70
|
+
email:
|
71
|
+
- steve@steveklabnik.com
|
72
|
+
executables:
|
73
|
+
- rerave
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- .gitignore
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/rerave
|
83
|
+
- lib/rerave.rb
|
84
|
+
- lib/rerave/archive.rb
|
85
|
+
- lib/rerave/cli.rb
|
86
|
+
- lib/rerave/version.rb
|
87
|
+
- rerave.gemspec
|
88
|
+
homepage: http://github.com/steveklabnik/rerave
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.0.3
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Calculate score statistics for ReRave.
|
112
|
+
test_files: []
|