fantasy-football 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/fantasyfootball +1 -1
- data/fantasy-football.gemspec +1 -1
- data/lib/fantasy-football.rb +2 -2
- data/lib/fantasy_football/CLI.rb +12 -12
- data/lib/fantasy_football/player.rb +2 -2
- data/lib/fantasy_football/scraper.rb +7 -30
- data/lib/fantasy_football/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b11fbd88cf3dfc178a6686a488e6aedd727ff6dce636c86913fd9e9429b3db0b
|
4
|
+
data.tar.gz: 6b6d3478c7e35b64ce53a9ca83676a6358b3b468e38e54257293db12f6880480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f5443603c4e01c885773f05e0cf3d0dc5fee77941d8be3d6cd6eaa3be0610d88fafd8aef19e75335197b7f1810ae8f323329909ab159d16a82fead4842d15d5
|
7
|
+
data.tar.gz: dd8b855a019762ee120c9ad49400f2a46299561f059e930258b5c3b4c9fec14b5914833e5e0f9aa34c81f38953034edb8368d64e7ac049865e0b05353dcf24c4
|
data/bin/fantasyfootball
CHANGED
data/fantasy-football.gemspec
CHANGED
data/lib/fantasy-football.rb
CHANGED
data/lib/fantasy_football/CLI.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
class CLI
|
1
|
+
class FantasyFootball::CLI
|
2
2
|
|
3
3
|
POSITIONS = ["qb", "rb", "te", "wr", "k"]
|
4
4
|
|
@@ -12,10 +12,10 @@ class CLI
|
|
12
12
|
# Asks for position and lists top players ranked by Fantasypros
|
13
13
|
puts "What position would you like to see rankings for?"
|
14
14
|
puts "Please enter QB, RB, TE, WR, or K:"
|
15
|
-
|
16
|
-
if POSITIONS.include?(
|
17
|
-
Scraper.
|
18
|
-
print_rankings
|
15
|
+
self.position = gets.strip.downcase
|
16
|
+
if POSITIONS.include?(position)
|
17
|
+
FantasyFootball::Scraper.scrape_rankings(position) if FantasyFootball::Player.find_by_position(position) == []
|
18
|
+
print_rankings
|
19
19
|
choose_player
|
20
20
|
else
|
21
21
|
puts "Invalid entry - please enter a valid input:"
|
@@ -23,10 +23,10 @@ class CLI
|
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
|
-
def print_rankings
|
26
|
+
def print_rankings
|
27
27
|
# Iterates through Player.all to print player name and rankings by position
|
28
28
|
puts " "
|
29
|
-
puts "-- Top #{Scraper.size} #{
|
29
|
+
puts "-- Top #{FantasyFootball::Scraper.size} #{position.upcase}s for Week #{11} of #{Time.new.year} --"
|
30
30
|
Player.find_by_position(position).sort {|a,b| a.rank.to_i <=> b.rank.to_i}.each {|i| puts "#{i.rank}. #{i.name}"}
|
31
31
|
puts " "
|
32
32
|
end
|
@@ -35,7 +35,7 @@ class CLI
|
|
35
35
|
# Prompts for player rank #, outputs player details
|
36
36
|
puts "If you would like to see details about a player, enter their rank number. If not, enter N:"
|
37
37
|
rank = gets.strip
|
38
|
-
if rank.to_i.between?(1,Scraper.size)
|
38
|
+
if rank.to_i.between?(1,FantasyFootball::Scraper.size)
|
39
39
|
print_player(rank)
|
40
40
|
elsif rank.downcase == "n"
|
41
41
|
return
|
@@ -45,11 +45,11 @@ class CLI
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def print_player(
|
48
|
+
def print_player(rank)
|
49
49
|
# Prints specific player using a custom class finder
|
50
50
|
blank = " "
|
51
|
-
p = Player.find_by_rank_and_position(
|
52
|
-
Scraper.
|
51
|
+
p = FantasyFootball::Player.find_by_rank_and_position(rank, position)
|
52
|
+
FantasyFootball::Scraper.add_attr(p)
|
53
53
|
puts blank
|
54
54
|
puts " Player Stats "
|
55
55
|
puts "------------------------------- "
|
@@ -71,7 +71,7 @@ class CLI
|
|
71
71
|
puts "Please enter 1, 2, or quit."
|
72
72
|
input = gets.strip.downcase
|
73
73
|
if input == "1"
|
74
|
-
print_rankings
|
74
|
+
print_rankings
|
75
75
|
choose_player
|
76
76
|
elsif input == "2"
|
77
77
|
choose_rankings
|
@@ -1,9 +1,9 @@
|
|
1
|
-
class Player
|
1
|
+
class FantasyFootball::Player
|
2
2
|
|
3
3
|
extend Findable::ClassMethods
|
4
4
|
include Memorable::InstanceMethods
|
5
5
|
|
6
|
-
attr_accessor :name, :position, :projection, :team, :height, :weight, :age, :college, :rank, :url
|
6
|
+
attr_accessor :name, :position, :projection, :team, :height, :weight, :age, :college, :rank, :url
|
7
7
|
|
8
8
|
@@all = []
|
9
9
|
|
@@ -1,44 +1,22 @@
|
|
1
|
-
class Scraper
|
2
|
-
|
3
|
-
extend Findable::ClassMethods
|
4
|
-
include Memorable::InstanceMethods
|
5
|
-
|
6
|
-
attr_accessor :name, :week
|
7
|
-
|
8
|
-
@@all = []
|
9
|
-
|
10
|
-
def self.all # Class variable reader
|
11
|
-
@@all
|
12
|
-
end
|
1
|
+
class FantasyFootball::Scraper
|
13
2
|
|
14
3
|
def self.size #Determines how many players to scrape per position
|
15
4
|
20
|
16
5
|
end
|
17
6
|
|
18
|
-
def self.
|
19
|
-
if !Scraper.find_by_name(name)
|
20
|
-
s = Scraper.new
|
21
|
-
s.name = name
|
22
|
-
s.save
|
23
|
-
s.scrape_rankings(name)
|
24
|
-
else
|
25
|
-
Scraper.find_by_name(name)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def scrape_rankings(position)
|
7
|
+
def self.scrape_rankings(position)
|
30
8
|
doc = Nokogiri::HTML(open("https://www.fantasypros.com/nfl/rankings/#{position}.php"))
|
31
9
|
# binding.pry
|
32
10
|
@week = doc.css('h1').text.split[5]
|
33
11
|
table = doc.css('tbody tr') # Selects the HTML table with player rankings
|
34
|
-
build_players(table,
|
12
|
+
build_players(table, position)
|
35
13
|
end
|
36
14
|
|
37
|
-
def build_players(table,position)
|
15
|
+
def self.build_players(table,position)
|
38
16
|
# Input is HTML table of player rankings, instantiates Players, assigns name, rank, and url
|
39
17
|
table.each_with_index do |t, i|
|
40
18
|
if i < Scraper.size
|
41
|
-
p = Player.new
|
19
|
+
p = FantasyFootball::Player.new
|
42
20
|
p.name = [t.text.split[1], t.text.split[3]].join(" ")
|
43
21
|
p.rank = t.text.split[0]
|
44
22
|
p.url = "https://www.fantasypros.com" + t.css('a')[0]["href"]
|
@@ -47,9 +25,9 @@ class Scraper
|
|
47
25
|
end
|
48
26
|
end
|
49
27
|
|
50
|
-
def add_attr(player)
|
28
|
+
def self.add_attr(player)
|
51
29
|
# Scrapes player url stored in Player instance and assigns additional attributes
|
52
|
-
if player.
|
30
|
+
if player.height == nil
|
53
31
|
rescue_s = "n/a"
|
54
32
|
doc = Nokogiri::HTML(open(player.url))
|
55
33
|
player.projection = doc.css('.clearfix.detail span.pull-right')[2].text.split[0]
|
@@ -58,7 +36,6 @@ class Scraper
|
|
58
36
|
player.weight = doc.css('span.bio-detail')[1].text[8,3]
|
59
37
|
player.age = doc.css('span.bio-detail')[2].text[5,2]
|
60
38
|
player.college = (doc.css('span.bio-detail')[3].text.split(": ")[1].to_s rescue rescue_s)
|
61
|
-
player.scraped = "Y"
|
62
39
|
end
|
63
40
|
end
|
64
41
|
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.1.
|
1
|
+
module FantasyFootball
|
2
|
+
VERSION = "0.1.6"
|
3
3
|
end
|