world_cup_cli 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.
- checksums.yaml +7 -0
- data/bin/world_cup_cli +2 -0
- data/config/environment.rb +8 -0
- data/lib/scores.rb +30 -0
- data/lib/scores_scraper.rb +39 -0
- data/lib/standings.rb +21 -0
- data/lib/standings_scraper.rb +44 -0
- data/lib/world_cup_cli.rb +24 -0
- metadata +80 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a74f585a6bc52df34d5c2defd03db447ef3e142
|
4
|
+
data.tar.gz: 620b0cd481938ff004429633fa36a53a292abd26
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 58d9da6348df3192e10345b648360f1490926ff1674828ae85e89253eee04abcb79a370f5f66dc11193871eb3cd4620c807af6ab14cc189e88d455b6a74ee5e1
|
7
|
+
data.tar.gz: 6d6df6dcabffbef93ce1911f27156e68ac38e62456302afae93144fc18af7b989b064050523c9bf28a67bdfca2c4030f3ec40ae8dde3eeb5506c061d44414874
|
data/bin/world_cup_cli
ADDED
data/lib/scores.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
class Scores
|
2
|
+
def self.updated_at
|
3
|
+
Time.now.strftime('%D %T')
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.latest_updates
|
7
|
+
puts "\n\nScores and upcoming matches updated as of #{Scores.updated_at}".colorize(:yellow)
|
8
|
+
scores = ScoresScraper.new.match_array
|
9
|
+
puts "Yesterday's results".colorize(:light_blue) unless scores[:yesterday].empty?
|
10
|
+
display_results(scores[:yesterday])
|
11
|
+
puts "\n"
|
12
|
+
puts "Today's matches and results".colorize(:light_blue) unless scores[:today].empty?
|
13
|
+
display_results(scores[:today])
|
14
|
+
puts "\n"
|
15
|
+
puts "Tomorrow's upcoming matches".colorize(:light_blue) unless scores[:tomorrow].empty?
|
16
|
+
display_results(scores[:tomorrow])
|
17
|
+
return
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.display_results(arr)
|
21
|
+
arr.each do |match|
|
22
|
+
display_match(match)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.display_match(match)
|
27
|
+
puts "#{match[:home_team]} #{match[:score]} #{match[:away_team]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class ScoresScraper
|
2
|
+
def initialize
|
3
|
+
@uri = 'http://www.fifa.com/worldcup/matches/index.html'
|
4
|
+
end
|
5
|
+
|
6
|
+
def request
|
7
|
+
Nokogiri::HTML(open(@uri))
|
8
|
+
end
|
9
|
+
|
10
|
+
def pulled_data
|
11
|
+
self.request.css('.col-xs-3 div')
|
12
|
+
end
|
13
|
+
|
14
|
+
def match_array
|
15
|
+
arr = [ ]
|
16
|
+
self.pulled_data.each do |match|
|
17
|
+
arr << {
|
18
|
+
date: convert_to_datetime(match.children.css('.mu-i-datetime').text),
|
19
|
+
home_team: match.children.css('.t.home span.t-nTri').text,
|
20
|
+
away_team: match.children.css('.t.away span.t-nTri').text,
|
21
|
+
score: match.children.css('.s span.s-scoreText').text
|
22
|
+
}
|
23
|
+
end
|
24
|
+
clean_array = arr.select{|item| item unless invalid_match?(item)}
|
25
|
+
yesterday = clean_array.select{|s| s if s[:date].to_date == Date.today - 1}
|
26
|
+
today = clean_array.select{|s| s if s[:date].to_date == Date.today}
|
27
|
+
tomorrow = clean_array.select{|s| s if s[:date].to_date == Date.today + 1}
|
28
|
+
{ yesterday: yesterday, today: today, tomorrow: tomorrow }
|
29
|
+
end
|
30
|
+
|
31
|
+
def convert_to_datetime(string)
|
32
|
+
DateTime.strptime(string, '%d %b %Y - %H:%M') unless string.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
def invalid_match?(item)
|
36
|
+
item[:date].class != DateTime || item[:home_team].empty?
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
data/lib/standings.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
class Standings
|
2
|
+
def self.header
|
3
|
+
"Country W D L GF GA Pts" # 47 chars
|
4
|
+
end
|
5
|
+
|
6
|
+
def self.updated_at
|
7
|
+
Time.now.strftime('%D %T')
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.latest_updates
|
11
|
+
puts "\n\nStandings as of #{Standings.updated_at}".colorize(:yellow)
|
12
|
+
StandingsScraper.new.groups_array.each do |group|
|
13
|
+
puts "\n #{group[:name]} "
|
14
|
+
puts Standings.header
|
15
|
+
group[:countries].each do |country|
|
16
|
+
puts "#{country[:name]} #{country[:wins]} #{country[:draws]} #{country[:losses]} #{country[:goals_for]} #{country[:goals_against]} #{country[:points]}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
puts "\n"
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class StandingsScraper
|
2
|
+
def initialize
|
3
|
+
@uri = 'http://www.fifa.com/worldcup/groups/index.html'
|
4
|
+
end
|
5
|
+
|
6
|
+
def request
|
7
|
+
Nokogiri::HTML(open(@uri))
|
8
|
+
end
|
9
|
+
|
10
|
+
def pulled_data
|
11
|
+
self.request.css('.group-wrap')
|
12
|
+
end
|
13
|
+
|
14
|
+
def groups_array
|
15
|
+
arr = [ ]
|
16
|
+
self.pulled_data.each do |group|
|
17
|
+
arr << {
|
18
|
+
name: group.css('.caption-nolink').text,
|
19
|
+
countries: countries_array(group.css('tr'))
|
20
|
+
}
|
21
|
+
end
|
22
|
+
return arr
|
23
|
+
end
|
24
|
+
|
25
|
+
def countries_array(countries)
|
26
|
+
arr = [ ]
|
27
|
+
countries.each do |country|
|
28
|
+
arr << {
|
29
|
+
name: country.css('.tbl-teamcode .t-nTri').text,
|
30
|
+
wins: country.css('.tbl-win span.text').text,
|
31
|
+
draws: country.css('.tbl-draw span.text').text,
|
32
|
+
losses: country.css('.tbl-lost span.text').text,
|
33
|
+
goals_for: country.css('.tbl-goalfor span.text').text,
|
34
|
+
goals_against: country.css('.tbl-goalagainst span.text').text,
|
35
|
+
points: country.css('.tbl-pts span.text').text
|
36
|
+
}
|
37
|
+
end
|
38
|
+
arr.select{ |item| item unless item[:name].empty? }
|
39
|
+
end
|
40
|
+
|
41
|
+
def not_present?(country_name)
|
42
|
+
country_name.empty?
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../config/environment.rb'
|
3
|
+
|
4
|
+
banner = "* World Cup CLI: Quickly check table standings and scores *"
|
5
|
+
|
6
|
+
opt_parser = OptionParser.new do |opt|
|
7
|
+
opt.banner = ("\n" + "*" * banner.length + "\n" + banner + "\n" + "*" * banner.length).colorize(:light_blue)
|
8
|
+
opt.separator "Commands".colorize(:red)
|
9
|
+
opt.separator " standings: See latest group table standings".colorize(:red)
|
10
|
+
opt.separator " scores: See scores and upcoming matches".colorize(:red)
|
11
|
+
opt.separator ""
|
12
|
+
opt.separator "Usage example: world_cup_cli standings"
|
13
|
+
end
|
14
|
+
|
15
|
+
opt_parser.parse!
|
16
|
+
|
17
|
+
case ARGV[0]
|
18
|
+
when "standings"
|
19
|
+
puts Standings.latest_updates
|
20
|
+
when "scores"
|
21
|
+
puts Scores.latest_updates
|
22
|
+
else
|
23
|
+
puts opt_parser
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: world_cup_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Stubblefield
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-12 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.6.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.2
|
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.7.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.7.3
|
41
|
+
description: A command line interface to quickly check table standings, scores, and
|
42
|
+
upcoming matches for the World Cup
|
43
|
+
email: jameswilliamiii@gmail.com
|
44
|
+
executables:
|
45
|
+
- world_cup_cli
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- config/environment.rb
|
50
|
+
- lib/scores.rb
|
51
|
+
- lib/scores_scraper.rb
|
52
|
+
- lib/standings.rb
|
53
|
+
- lib/standings_scraper.rb
|
54
|
+
- lib/world_cup_cli.rb
|
55
|
+
- bin/world_cup_cli
|
56
|
+
homepage: https://github.com/jameswilliamiii/world_cup_cli
|
57
|
+
licenses:
|
58
|
+
- MIT
|
59
|
+
metadata: {}
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
requirements: []
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 2.1.11
|
77
|
+
signing_key:
|
78
|
+
specification_version: 4
|
79
|
+
summary: world cup 2014 tables and scores
|
80
|
+
test_files: []
|