intermat-scrape 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 +7 -0
- data/bin/intermat-scrape +5 -0
- data/config/environment.rb +10 -0
- data/lib/intermat_scrape.rb +5 -0
- data/lib/intermat_scrape/cli.rb +124 -0
- data/lib/intermat_scrape/scraper.rb +21 -0
- data/lib/intermat_scrape/version.rb +3 -0
- data/lib/intermat_scrape/weight_class.rb +49 -0
- data/lib/intermat_scrape/wrestler.rb +31 -0
- metadata +136 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 12b06c1a2f315508f6e2b207eb143068b42a545186a5752b951a56284990c9da
|
4
|
+
data.tar.gz: e6867326a6edc5597d5bba58ef4eb864a0f427fd523878199e5ef875270c220f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20931e49de05be17d07be0023fc6a32c6ab5067fa47fd662984f9ec44fad3d9ede4e7f2099ebed4602c1798203134021d3183f20496033ecb8899e230012dae1
|
7
|
+
data.tar.gz: 477acaf1914d82b5a3705b8531774e2fcb78d2b60c5b171e32741293cfe6ba298bd91c7809fb002aa528bb8497246987a808f3a4e85f3d9ccb7df6db65e06d50
|
data/bin/intermat-scrape
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require "nokogiri"
|
2
|
+
require "open-uri"
|
3
|
+
require "pry"
|
4
|
+
require "colorize"
|
5
|
+
|
6
|
+
require_relative "../lib/intermat_scrape/cli"
|
7
|
+
require_relative "../lib/intermat_scrape/scraper"
|
8
|
+
require_relative "../lib/intermat_scrape/version"
|
9
|
+
require_relative "../lib/intermat_scrape/weight_class"
|
10
|
+
require_relative "../lib/intermat_scrape/wrestler"
|
@@ -0,0 +1,124 @@
|
|
1
|
+
class IntermatScrape::Cli
|
2
|
+
def load_data
|
3
|
+
IntermatScrape::WeightClass.create_weight_classes
|
4
|
+
IntermatScrape::WeightClass.all.each do |weight_class|
|
5
|
+
IntermatScrape::Scraper.create_wrestlers(weight_class)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def flow
|
10
|
+
welcome
|
11
|
+
load_data
|
12
|
+
start
|
13
|
+
end
|
14
|
+
|
15
|
+
def welcome
|
16
|
+
puts '-----------------------------------------------------------------'
|
17
|
+
puts ''
|
18
|
+
puts 'Welcome to IntermatScrape, a way to delve into the top 20 ranked'
|
19
|
+
puts ' NCAA wrestlers.'
|
20
|
+
puts ''
|
21
|
+
puts ' LOADING...'
|
22
|
+
puts ''
|
23
|
+
puts '-----------------------------------------------------------------'
|
24
|
+
end
|
25
|
+
|
26
|
+
def start
|
27
|
+
if weight_class = choose_weight
|
28
|
+
choose_rank(weight_class)
|
29
|
+
if restart?
|
30
|
+
start
|
31
|
+
else
|
32
|
+
choose_rank(weight_class)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def quit_scraper
|
38
|
+
puts ''
|
39
|
+
puts 'Thank you for using IntermatScrape!'
|
40
|
+
exit
|
41
|
+
end
|
42
|
+
|
43
|
+
def choose_weight
|
44
|
+
weight_class = nil
|
45
|
+
puts ''
|
46
|
+
puts 'What weight class are you interested in?'
|
47
|
+
puts ''
|
48
|
+
IntermatScrape::WeightClass.print_weights
|
49
|
+
|
50
|
+
input = gets.strip
|
51
|
+
until IntermatScrape::WeightClass::WEIGHT_CLASSES.include?(input)
|
52
|
+
puts "I don't recognize that weight class. Please try again."
|
53
|
+
input = gets.strip
|
54
|
+
end
|
55
|
+
|
56
|
+
puts ''
|
57
|
+
puts 'Type one of the following commands:'
|
58
|
+
puts 'rankings(r):'.colorize(:light_cyan).concat(' show top 20 wrestlers')
|
59
|
+
puts 'back(b):'.colorize(:light_cyan).concat(' return to weight classes')
|
60
|
+
puts 'exit:'.colorize(:light_cyan).concat(' exit program')
|
61
|
+
puts ''
|
62
|
+
command = gets.strip.downcase
|
63
|
+
until %w[rankings r back b exit].include?(command)
|
64
|
+
puts 'Invalid command. Please type a valid command.'
|
65
|
+
command = gets.strip.downcase
|
66
|
+
end
|
67
|
+
|
68
|
+
case command
|
69
|
+
when 'rankings', 'r'
|
70
|
+
weight_class = IntermatScrape::WeightClass.find_by_weight(input)
|
71
|
+
when 'back', 'b'
|
72
|
+
start
|
73
|
+
when 'exit'
|
74
|
+
quit_scraper
|
75
|
+
end
|
76
|
+
weight_class
|
77
|
+
end
|
78
|
+
|
79
|
+
def choose_rank(weight_class)
|
80
|
+
weight_class.print_wrestlers
|
81
|
+
puts ''
|
82
|
+
puts 'Type one of the following commands:'
|
83
|
+
puts 'a number 1-20'.colorize(:light_cyan).concat(' to view the corresponding wrestler')
|
84
|
+
puts 'back(b):'.colorize(:light_cyan).concat(' return to weight classes')
|
85
|
+
puts 'exit:'.colorize(:light_cyan).concat(' exit program')
|
86
|
+
puts ''
|
87
|
+
command = gets.strip.downcase
|
88
|
+
until %w[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 back b exit].include?(command)
|
89
|
+
puts 'Invalid command. Please enter a valid command.'
|
90
|
+
command = gets.strip.downcase
|
91
|
+
end
|
92
|
+
|
93
|
+
case command
|
94
|
+
when '1'..'20'
|
95
|
+
weight_class.get_wrestler_by_rank(command).to_s
|
96
|
+
when 'back', 'b'
|
97
|
+
start
|
98
|
+
when 'exit'
|
99
|
+
quit_scraper
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def restart?
|
104
|
+
puts ''
|
105
|
+
puts 'Would you like to do now?'
|
106
|
+
puts 'view(v):'.colorize(:light_cyan).concat(' view another wrestler from this weight class')
|
107
|
+
puts 'back(b):'.colorize(:light_cyan).concat(' return to weight classes')
|
108
|
+
puts 'exit:'.colorize(:light_cyan).concat(' exit program')
|
109
|
+
puts ''
|
110
|
+
command = gets.strip.downcase
|
111
|
+
until %w[view v back b exit].include?(command)
|
112
|
+
puts 'Invalid command. Please type a valid command.'
|
113
|
+
command = gets.strip.downcase
|
114
|
+
end
|
115
|
+
case command
|
116
|
+
when 'view', 'v'
|
117
|
+
false
|
118
|
+
when 'back', 'b'
|
119
|
+
true
|
120
|
+
when 'exit'
|
121
|
+
quit_scraper
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class IntermatScrape::Scraper
|
2
|
+
attr_accessor :weight_class
|
3
|
+
|
4
|
+
BASE_URL = 'https://www.intermatwrestle.com/rankings/college/'.freeze
|
5
|
+
|
6
|
+
def self.get_doc_by_weight(weight_class)
|
7
|
+
Nokogiri::HTML(open(BASE_URL + weight_class.weight))
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.get_rows(weight_class)
|
11
|
+
get_doc_by_weight(weight_class).css('table.table tbody tr')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create_wrestlers(weight_class)
|
15
|
+
get_rows(weight_class).collect do |row|
|
16
|
+
IntermatScrape::Wrestler.new_by_row(row).tap do |w|
|
17
|
+
weight_class.add_wrestler(w)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class IntermatScrape::WeightClass
|
2
|
+
attr_accessor :wrestlers, :weight
|
3
|
+
|
4
|
+
WEIGHT_CLASSES = %w[125 133 141 149 157 165 174 184 197 Hwt].freeze
|
5
|
+
|
6
|
+
@@all = []
|
7
|
+
|
8
|
+
def initialize(weight)
|
9
|
+
@weight = weight
|
10
|
+
@wrestlers = []
|
11
|
+
@@all << self
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create_weight_classes
|
15
|
+
WEIGHT_CLASSES.each do |weight|
|
16
|
+
new(weight)
|
17
|
+
end
|
18
|
+
@@all
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.print_weights
|
22
|
+
puts WEIGHT_CLASSES
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find_by_weight(weight)
|
26
|
+
@@all.detect { |w| w.weight == weight }
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_wrestler(wrestler)
|
30
|
+
@wrestlers << wrestler
|
31
|
+
wrestler.weight_class = self
|
32
|
+
end
|
33
|
+
|
34
|
+
# TODO: move to Wrestler class?
|
35
|
+
def print_wrestlers
|
36
|
+
puts ""
|
37
|
+
puts "Rankings: ".colorize(:light_cyan)
|
38
|
+
@wrestlers.each.with_index { |w, _i| puts "#{w.rank}\t#{w.name}" }
|
39
|
+
end
|
40
|
+
|
41
|
+
# TODO: move to Wrestler class?
|
42
|
+
def get_wrestler_by_rank(rank)
|
43
|
+
@wrestlers.detect { |w| w.rank == rank }
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.all
|
47
|
+
@@all
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
class IntermatScrape::Wrestler
|
2
|
+
attr_accessor :rank, :weight_class, :school, :class_standing, :conference
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(rank, name, school, class_standing, conference)
|
6
|
+
@rank = rank
|
7
|
+
@name = name
|
8
|
+
@school = school
|
9
|
+
@class_standing = class_standing
|
10
|
+
@conference = conference
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.new_by_row(row)
|
14
|
+
new(
|
15
|
+
row.children[1].text,
|
16
|
+
row.css(':nth-child(2) a').text,
|
17
|
+
row.css(':nth-child(3)').text,
|
18
|
+
row.css(':nth-child(4)').text,
|
19
|
+
row.css(':nth-child(5)').text
|
20
|
+
)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
puts ''
|
25
|
+
puts "----------- #{name} ##{rank} -----------".on_blue
|
26
|
+
puts ''
|
27
|
+
puts "School:".colorize(:light_cyan).ljust(20).concat(@school)
|
28
|
+
puts "Class:".colorize(:light_cyan).ljust(20).concat(@class_standing)
|
29
|
+
puts "Conference:".colorize(:light_cyan).ljust(20).concat(@conference)
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: intermat-scrape
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Dawson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
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.17'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.17'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description:
|
98
|
+
email:
|
99
|
+
- dannyldawson@gmail.com
|
100
|
+
executables:
|
101
|
+
- intermat-scrape
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- bin/intermat-scrape
|
106
|
+
- config/environment.rb
|
107
|
+
- lib/intermat_scrape.rb
|
108
|
+
- lib/intermat_scrape/cli.rb
|
109
|
+
- lib/intermat_scrape/scraper.rb
|
110
|
+
- lib/intermat_scrape/version.rb
|
111
|
+
- lib/intermat_scrape/weight_class.rb
|
112
|
+
- lib/intermat_scrape/wrestler.rb
|
113
|
+
homepage: http://rubygems.org/gems/intermat-scrape
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubygems_version: 3.0.1
|
133
|
+
signing_key:
|
134
|
+
specification_version: 4
|
135
|
+
summary: Provides ranking information for the top 20 NCAA wrestlers at each weight.
|
136
|
+
test_files: []
|