footty 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a9e350f6c69753563babe7b6313e990333d20f8a
4
- data.tar.gz: 9abbd3a090529c2d6dceb8f5cb4a30c09032885a
2
+ SHA256:
3
+ metadata.gz: 879022e67b5a32b7c48593dbe546a6fc3ceeba3a14bc2e64ecc6e6cea6004b0a
4
+ data.tar.gz: b9075358a339760d56d5ac282a71859d1154002100e20b142d4f1dab44562676
5
5
  SHA512:
6
- metadata.gz: 9fb986e01c99f9ce33b1ebb04e321af30c85570967c42a046029c3c70726a57e38a56a8f217792959cebe9d59313962407af8ca54a07c4a2af07f422812751ad
7
- data.tar.gz: dae5fdad18c6f894f01e991d5bc0db5f9345fbde968edf3d42b4f3407c79a31e2678af30269d2b24d67b419e1d8f1602d6a856bad70828aa0c08b87f93d31979
6
+ metadata.gz: 12825097748d31665a168847c9aa0c017fbd21cc4353b7d9917ebaf0553ef1b0b7ab34995c7c8f5c8f0da2b7d740ce7c12ac3b7d113bdd85f58f07d480fa41d8
7
+ data.tar.gz: 8c7719e5dc9403397c4feaa10886acf04f5d2bc329f81f4a9069948ec4c17f379cab1c836f573099b9968b673b5b152b7e977e9885bf31c348e384e891a114a7
@@ -1,3 +1,3 @@
1
- ### 1.0.0 / 2018-06-09
2
-
3
- * Everything is new (again). First release.
1
+ ### 1.0.0 / 2018-06-09
2
+
3
+ * Everything is new (again). First release.
data/Manifest.txt CHANGED
@@ -1,4 +1,4 @@
1
- HISTORY.md
1
+ CHANGELOG.md
2
2
  Manifest.txt
3
3
  README.md
4
4
  Rakefile
@@ -7,4 +7,5 @@ lib/footty.rb
7
7
  lib/footty/client.rb
8
8
  lib/footty/version.rb
9
9
  test/helper.rb
10
- test/test_client.rb
10
+ test/test_client_euro.rb
11
+ test/test_client_worldcup.rb
data/README.md CHANGED
@@ -1,80 +1,86 @@
1
- # footty - football.db command line client for world cup (russia 2018) and more
2
-
3
- * home :: [github.com/sportdb/footty](https://github.com/sportdb/footty)
4
- * bugs :: [github.com/sportdb/footty/issues](https://github.com/sportdb/footty/issues)
5
- * gem :: [rubygems.org/gems/footty](https://rubygems.org/gems/footty)
6
- * rdoc :: [rubydoc.info/gems/footty](http://rubydoc.info/gems/footty)
7
- * forum :: [opensport](http://groups.google.com/group/opensport)
8
-
9
-
10
-
11
-
12
-
13
- ## Usage - Who's playing today?
14
-
15
- The footty command line tool lets you query the online football.db HTTP JSON API services
16
- for upcoming or past matches. For example:
17
-
18
- $ footty # Defaults to today's world cup 2018 matches
19
-
20
- prints on Jun/14 2018:
21
-
22
- #1 Thu Jun/14 Russia (RUS) 5-0 Saudi Arabia (KSA) Group A @ Luzhniki Stadium, Moscow
23
- [Gazinsky 12' Cheryshev 43' Dzyuba 71' Cheryshev 90+1' Golovin 90+4']
24
-
25
- prints on Jun/15 2018:
26
-
27
- #2 Fri Jun/15 Egypt (EGY) vs Uruguay (URU) Group A @ Ekaterinburg Arena, Ekaterinburg
28
- #3 Fri Jun/15 Portugal (POR) vs Spain (ESP) Group B @ Fisht Stadium, Sochi
29
- #4 Fri Jun/15 Morocco (MAR) vs Iran (IRN) Group B @ Saint Petersburg Stadium, Saint Petersburg
30
-
31
- prints on Jun/16:
32
-
33
- #5 Sat Jun/16 France (FRA) vs Australia (AUS) Group C @ Kazan Arena, Kazan
34
- #6 Sat Jun/16 Peru (PER) vs Denmark (DEN) Group C @ Mordovia Arena, Saransk
35
- #7 Sat Jun/16 Argentina (ARG) vs Iceland (ISL) Group D @ Spartak Stadium, Moscow
36
- #8 Sat Jun/16 Croatia (CRO) vs Nigeria (NGA) Group D @ Kaliningrad Stadium, Kaliningrad
37
-
38
- and so on.
39
- Use `tomorrow` or `t` or `+1` to print tomorrow's matches e.g.:
40
-
41
- $ footty tomorrow # -or-
42
- $ footty t
43
-
44
- Use `yesterday` or `y` or `-1` to print yesterday's matches e.g.:
45
-
46
- $ footty yesterday # -or-
47
- $ footty y
48
-
49
- Use `upcoming` or `up` or `u` to print all upcoming matches e.g.:
50
-
51
- $ footty upcoming # -or-
52
- $ footty up
53
-
54
- Use `past` or `p` to print all past matches e.g.:
55
-
56
- $ footty past # -or-
57
- $ footty p
58
-
59
-
60
- That's it. Enjoy the beautiful game.
61
-
62
-
63
- ## Install
64
-
65
- Just install the gem:
66
-
67
- $ gem install footty
68
-
69
-
70
- ## License
71
-
72
- The `footty` scripts are dedicated to the public domain.
73
- Use it as you please with no restrictions whatsoever.
74
-
75
-
76
- ## Questions? Comments?
77
-
78
- Send them along to the
79
- [Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
80
- Thanks!
1
+ # footty - football.db command line client for european ("euro") championship 2020 (in 2021) and more
2
+
3
+ * home :: [github.com/sportdb/footty](https://github.com/sportdb/footty)
4
+ * bugs :: [github.com/sportdb/footty/issues](https://github.com/sportdb/footty/issues)
5
+ * gem :: [rubygems.org/gems/footty](https://rubygems.org/gems/footty)
6
+ * rdoc :: [rubydoc.info/gems/footty](http://rubydoc.info/gems/footty)
7
+ * forum :: [opensport](http://groups.google.com/group/opensport)
8
+
9
+
10
+
11
+
12
+
13
+ ## Usage - Who's playing today?
14
+
15
+ The footty command line tool lets you query the online football.db HTTP JSON API services
16
+ for upcoming or past matches. For example:
17
+
18
+ $ footty # Defaults to today's euro 2020 (in 2021) matches
19
+
20
+ prints on Jun/14 2021:
21
+
22
+ #20 Mon Jun/14 Scotland (SCO) vs Czech Republic (CZE) Group D / Matchday 1
23
+ #25 Mon Jun/14 Poland (POL) vs Slovakia (SVK) Group E / Matchday 1
24
+ #26 Mon Jun/14 Spain (ESP) vs Sweden (SWE) Group E / Matchday 1
25
+
26
+ and the next day with `footty yesterday`:
27
+
28
+ #20 Mon Jun/14 Scotland (SCO) 0-2 (0-1) Czech Republic (CZE) Group D / Matchday 1
29
+ #25 Mon Jun/14 Poland (POL) 1-2 (0-1) Slovakia (SVK) Group E / Matchday 1
30
+ #26 Mon Jun/14 Spain (ESP) 0-0 Sweden (SWE) Group E / Matchday 1
31
+
32
+ prints on Jun/15 2021:
33
+
34
+ #31 Tue Jun/15 Hungary (HUN) vs Portugal (POR) Group F / Matchday 1
35
+ #32 Tue Jun/15 France (FRA) vs Germany (GER) Group F / Matchday 1
36
+
37
+ and so on.
38
+ Use `tomorrow` or `t` or `+1` to print tomorrow's matches e.g.:
39
+
40
+ $ footty tomorrow # -or-
41
+ $ footty t
42
+
43
+ Use `yesterday` or `y` or `-1` to print yesterday's matches e.g.:
44
+
45
+ $ footty yesterday # -or-
46
+ $ footty y
47
+
48
+ Use `upcoming` or `up` or `u` to print all upcoming matches e.g.:
49
+
50
+ $ footty upcoming # -or-
51
+ $ footty up
52
+
53
+ Use `past` or `p` to print all past matches e.g.:
54
+
55
+ $ footty past # -or-
56
+ $ footty p
57
+
58
+
59
+ That's it. Enjoy the beautiful game.
60
+
61
+
62
+
63
+
64
+ ## Trivia
65
+
66
+ Why tty? tty stands for teletype (tty) writer and is the old traditional (short) name for the unix command line.
67
+
68
+
69
+ ## Install
70
+
71
+ Just install the gem:
72
+
73
+ $ gem install footty
74
+
75
+
76
+ ## License
77
+
78
+ The `footty` scripts are dedicated to the public domain.
79
+ Use it as you please with no restrictions whatsoever.
80
+
81
+
82
+ ## Questions? Comments?
83
+
84
+ Send them along to the
85
+ [Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
86
+ Thanks!
data/Rakefile CHANGED
@@ -1,30 +1,30 @@
1
- require 'hoe'
2
- require './lib/footty/version.rb'
3
-
4
- Hoe.spec 'footty' do
5
-
6
- self.version = Footty::VERSION
7
-
8
- self.summary = 'footty - football.db command line client for world cup (russia 2018) and more - who is playing today?'
9
- self.description = summary
10
-
11
- self.urls = ['https://github.com/sportdb/footty']
12
-
13
- self.author = 'Gerald Bauer'
14
- self.email = 'opensport@googlegroups.com'
15
-
16
- # switch extension to .markdown for gihub formatting
17
- self.readme_file = 'README.md'
18
- self.history_file = 'HISTORY.md'
19
-
20
- self.extra_deps = [
21
- ['logutils' ],
22
- ['fetcher']
23
- ]
24
-
25
- self.licenses = ['Public Domain']
26
-
27
- self.spec_extras = {
28
- :required_ruby_version => '>= 2.3'
29
- }
30
- end
1
+ require 'hoe'
2
+ require './lib/footty/version.rb'
3
+
4
+ Hoe.spec 'footty' do
5
+
6
+ self.version = Footty::VERSION
7
+
8
+ self.summary = 'footty - football.db command line client for european "euro" championship 2020 (in 2021) and more - who is playing today?'
9
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/sportdb/footty' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'opensport@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ self.extra_deps = [
21
+ ['logutils' ],
22
+ ['fetcher']
23
+ ]
24
+
25
+ self.licenses = ['Public Domain']
26
+
27
+ self.spec_extras = {
28
+ required_ruby_version: '>= 2.3'
29
+ }
30
+ end
data/bin/footty CHANGED
@@ -1,5 +1,5 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'footty'
4
-
5
- Footty.main
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'footty'
4
+
5
+ Footty.main
data/lib/footty.rb CHANGED
@@ -1,152 +1,160 @@
1
- # encoding: utf-8
2
-
3
-
4
- ## stdlibs
5
-
6
- require 'net/http'
7
- require 'uri'
8
- require 'json'
9
- require 'pp'
10
-
11
-
12
- ## 3rd party gems/libs
13
- ## require 'props'
14
-
15
- require 'logutils'
16
- require 'fetcher'
17
-
18
- # our own code
19
-
20
- require 'footty/version' # let it always go first
21
- require 'footty/client'
22
-
23
-
24
- module Footty
25
-
26
- def self.client
27
- @@client ||= Client.new ## use "singelton" / shared client
28
- end
29
-
30
-
31
-
32
- def self.main
33
- puts banner # say hello
34
-
35
- what = ARGV[0] || 'today'
36
- what = what.downcase
37
-
38
- ## in the future make today "configurable" as param - why? why not?
39
- today = Date.today
40
-
41
- if ['yesterday', 'y', '-1'].include? what
42
- matches = client.get_yesterdays_matches
43
- if matches.empty?
44
- puts "** No matches played yesterday.\n"
45
- end
46
- elsif ['tomorrow', 't', '+1', '1'].include? what
47
- matches = client.get_tomorrows_matches
48
- if matches.empty?
49
- puts "** No matches scheduled tomorrow.\n"
50
- end
51
- elsif ['past', 'p', 'prev'].include? what
52
- matches = client.get_past_matches
53
- if matches.empty?
54
- puts "** No matches played yet.\n"
55
- end
56
- elsif ['upcoming', 'up', 'u', 'next', 'n'].include? what
57
- matches = client.get_upcoming_matches
58
- if matches.empty?
59
- puts "** No more matches scheduled.\n"
60
- end
61
- else
62
- matches = client.get_todays_matches
63
-
64
- ## no matches today
65
- if matches.empty?
66
- puts "** No matches scheduled today.\n"
67
-
68
- if Date.today > Date.new( 2018, 7, 11 ) ## world cup is over, look back
69
- puts "Past matches:"
70
- matches = client.get_past_matches
71
- else ## world cup is upcoming /in-progress,look forward
72
- puts "Upcoming matches:"
73
- matches = client.get_upcoming_matches
74
- end
75
- end
76
- end
77
-
78
- print_matches( matches )
79
- end
80
-
81
-
82
-
83
- def self.print_matches( matches )
84
- ## print games
85
-
86
- today = Date.today
87
-
88
- matches.each do |match|
89
- print " %5s" % "\##{match['num']} "
90
-
91
- date = Date.parse( match['date'] )
92
- print "#{date.strftime('%a %b/%d')} " ## e.g. Thu Jun/14
93
- if date > today
94
- diff = (date - today).to_i
95
- print "%10s" % "(in #{diff}d) "
96
- end
97
-
98
- print "%20s" % "#{match['team1']['name']} (#{match['team1']['code']})"
99
-
100
- if match['score1'] && match['score2']
101
- print " #{match['score1']}-#{match['score2']} "
102
- else
103
- print " vs "
104
- end
105
-
106
- print "%20s" % "#{match['team2']['name']} (#{match['team2']['code']})"
107
-
108
- if match['group']
109
- print " #{match['group']} " ## group phase/stage
110
- else
111
- print " #{match['round']} " ## knock out (k.o.) phase/stage
112
- end
113
-
114
- print " @ #{match['stadium']['name']}, #{match['city']}"
115
- print "\n"
116
-
117
- if match['goals1'] && match['goals2']
118
- print " ["
119
- match['goals1'].each_with_index do |goal,i|
120
- print " " if i > 0
121
- print "#{goal['name']}"
122
- print " #{goal['minute']}"
123
- print "+#{goal['offset']}" if goal['offset']
124
- print "'"
125
- print " (o.g.)" if goal['owngoal']
126
- print " (pen.)" if goal['penalty']
127
- end
128
- match['goals2'].each_with_index do |goal,i|
129
- if i == 0
130
- print "; "
131
- else
132
- print " "
133
- end
134
- print "#{goal['name']}"
135
- print " #{goal['minute']}"
136
- print "+#{goal['offset']}" if goal['offset']
137
- print "'"
138
- print " (o.g.)" if goal['owngoal']
139
- print " (pen.)" if goal['penalty']
140
- end
141
- print "]\n"
142
- end
143
-
144
-
145
- end
146
- end
147
-
148
- end # module Footty
149
-
150
-
151
-
152
- Footty.main if __FILE__ == $0
1
+ ## stdlibs
2
+
3
+ require 'net/http'
4
+ require 'uri'
5
+ require 'json'
6
+ require 'pp'
7
+
8
+
9
+ ## 3rd party gems/libs
10
+ ## require 'props'
11
+
12
+ require 'logutils'
13
+ require 'fetcher'
14
+
15
+
16
+ # our own code
17
+ require 'footty/version' # let it always go first
18
+ require 'footty/client'
19
+
20
+
21
+ module Footty
22
+
23
+ def self.client
24
+ ## note: hard code tournament / league for now
25
+ @client ||= Client.new( league: 'euro', year: 2020 ) ## use "singelton" / shared client
26
+ end
27
+
28
+
29
+
30
+ def self.main
31
+ puts banner # say hello
32
+
33
+ what = ARGV[0] || 'today'
34
+ what = what.downcase
35
+
36
+ ## in the future make today "configurable" as param - why? why not?
37
+ today = Date.today
38
+
39
+ if ['yesterday', 'y', '-1'].include?( what )
40
+ matches = client.yesterdays_matches
41
+ if matches.empty?
42
+ puts "** No matches played yesterday.\n"
43
+ end
44
+ elsif ['tomorrow', 't', '+1', '1'].include?( what )
45
+ matches = client.tomorrows_matches
46
+ if matches.empty?
47
+ puts "** No matches scheduled tomorrow.\n"
48
+ end
49
+ elsif ['past', 'p', 'prev'].include?( what )
50
+ matches = client.past_matches
51
+ if matches.empty?
52
+ puts "** No matches played yet.\n"
53
+ end
54
+ elsif ['upcoming', 'up', 'u', 'next', 'n'].include?( what )
55
+ matches = client.upcoming_matches
56
+ if matches.empty?
57
+ puts "** No more matches scheduled.\n"
58
+ end
59
+ else
60
+ matches = client.todays_matches
61
+
62
+ ## no matches today
63
+ if matches.empty?
64
+ puts "** No matches scheduled today.\n"
65
+
66
+ ## note: was world cup 2018 - end date -- Date.new( 2018, 7, 11 )
67
+ if Date.today > Date.new( 2021, 7, 11 ) ## tournament is over, look back
68
+ puts "Past matches:"
69
+ matches = client.past_matches
70
+ else ## world cup is upcoming /in-progress,look forward
71
+ puts "Upcoming matches:"
72
+ matches = client.upcoming_matches
73
+ end
74
+ end
75
+ end
76
+
77
+
78
+
79
+ print_matches( matches )
80
+ end
81
+
82
+
83
+
84
+ def self.print_matches( matches )
85
+ ## print games
86
+
87
+ today = Date.today
88
+
89
+ matches.each do |match|
90
+ print " %5s" % "\##{match['num']} "
91
+
92
+ date = Date.parse( match['date'] )
93
+ print "#{date.strftime('%a %b/%d')} " ## e.g. Thu Jun/14
94
+ if date > today
95
+ diff = (date - today).to_i
96
+ print "%10s" % "(in #{diff}d) "
97
+ end
98
+
99
+ print "%22s" % "#{match['team1']['name']} (#{match['team1']['code']})"
100
+
101
+ ## todo/fix: add support for knockout scores
102
+ ## with score1et/score1p (extra time and penalty)
103
+ if match['score1'] && match['score2']
104
+ print " #{match['score1']}-#{match['score2']} "
105
+ print "(#{match['score1i']}-#{match['score2i']}) "
106
+ else
107
+ print " vs "
108
+ end
109
+
110
+ print "%-22s" % "#{match['team2']['name']} (#{match['team2']['code']})"
111
+
112
+ if match['group']
113
+ print " #{match['group']} /" ## group phase/stage
114
+ end
115
+
116
+ print " #{match['round']} " ## knock out (k.o.) phase/stage
117
+
118
+ if match['stadium']
119
+ print " @ #{match['stadium']['name']}, #{match['city']}"
120
+ end
121
+
122
+ print "\n"
123
+
124
+
125
+ if match['goals1'] && match['goals2']
126
+ print " ["
127
+ match['goals1'].each_with_index do |goal,i|
128
+ print " " if i > 0
129
+ print "#{goal['name']}"
130
+ print " #{goal['minute']}"
131
+ print "+#{goal['offset']}" if goal['offset']
132
+ print "'"
133
+ print " (o.g.)" if goal['owngoal']
134
+ print " (pen.)" if goal['penalty']
135
+ end
136
+ match['goals2'].each_with_index do |goal,i|
137
+ if i == 0
138
+ print "; "
139
+ else
140
+ print " "
141
+ end
142
+ print "#{goal['name']}"
143
+ print " #{goal['minute']}"
144
+ print "+#{goal['offset']}" if goal['offset']
145
+ print "'"
146
+ print " (o.g.)" if goal['owngoal']
147
+ print " (pen.)" if goal['penalty']
148
+ end
149
+ print "]\n"
150
+ end
151
+
152
+
153
+ end
154
+ end
155
+
156
+ end # module Footty
157
+
158
+
159
+
160
+ Footty.main if __FILE__ == $0
data/lib/footty/client.rb CHANGED
@@ -1,103 +1,106 @@
1
- # encoding: utf-8
2
-
3
- module Footty
4
-
5
- class Client
6
-
7
- include LogUtils::Logging
8
-
9
- API_BASE = 'https://raw.githubusercontent.com/openfootball/world-cup.json/master/2018'
10
-
11
- def initialize( opts={} )
12
- @opts = opts
13
- @worker = Fetcher::Worker.new
14
- end
15
-
16
-
17
-
18
- ### note:
19
- ## cache ALL methods - only do one web request for worldcup match schedule & results
20
- def get_worldcup
21
- @worldcup ||= get( 'worldcup.json' ) ## use "memoized" / cached result
22
- end
23
-
24
-
25
-
26
-
27
-
28
- ## for testing lets you use /round/1 etc.
29
- def get_round( num )
30
- h = get_worldcup
31
- matches = h[ 'rounds' ][ num-1 ] ## note: rounds hash starts with zero (not 1)
32
- matches
33
- end
34
-
35
-
36
- def get_todays_matches( date: Date.today ) get_matches_for( date ); end
37
- def get_tomorrows_matches( date: Date.today ) get_matches_for( date+1 ); end
38
- def get_yesterdays_matches( date: Date.today ) get_matches_for( date-1 ); end
39
-
40
- def get_matches_for( date )
41
- hash = get_worldcup
42
- matches = select_matches( hash[ 'rounds' ] ) { |match| date == Date.parse( match['date'] ) }
43
- matches
44
- end
45
-
46
-
47
- def get_upcoming_matches( date: Date.today )
48
- ## note: includes todays matches for now
49
- hash = get_worldcup
50
- matches = select_matches( hash[ 'rounds' ] ) { |match| date <= Date.parse( match['date'] ) }
51
- matches
52
- end
53
-
54
- def get_past_matches( date: Date.today )
55
- hash = get_worldcup
56
- matches = select_matches( hash[ 'rounds' ] ) { |match| date > Date.parse( match['date'] ) }
57
- ## note reveserve matches (chronological order/last first)
58
- matches.reverse
59
- end
60
-
61
- private
62
-
63
- def select_matches( rounds )
64
- matches = []
65
- rounds.each do |round|
66
- round['matches'].each do |match|
67
- if yield( match )
68
- ## hack: add (outer) round to match
69
- match['round'] = round['name']
70
- matches << match
71
- else
72
- ## puts " skipping game play_date #{play_date}"
73
- end
74
- end
75
- end
76
- matches
77
- end
78
-
79
- def get( path )
80
- ## uri = URI.parse( "#{API_BASE}/#{path}" )
81
- # fix: use is_a? URI in fetcher
82
- uri_string = "#{API_BASE}/#{path}"
83
-
84
- response = @worker.get_response( uri_string )
85
-
86
- if response.code == '200'
87
- ##
88
- ## todo/check:
89
- ## do we need to force utf-8 encoding?
90
- ## check for teams w/ non-ascii names
91
- hash = JSON.parse( response.body )
92
- ## pp hash
93
- hash
94
- else
95
- logger.error "fetch HTTP - #{response.code} #{response.message}"
96
- nil
97
- end
98
- end
99
-
100
- end # class Client
101
-
102
-
103
- end # module Footty
1
+ module Footty
2
+
3
+
4
+ class Client
5
+
6
+ include LogUtils::Logging
7
+
8
+
9
+ def initialize( league:, year: )
10
+ @worker = Fetcher::Worker.new
11
+
12
+ @league = league
13
+ @year = year
14
+ end
15
+
16
+
17
+ APIS = {
18
+ worldcup: 'https://github.com/openfootball/worldcup.json/raw/master/$year$/worldcup.json',
19
+ euro: 'https://github.com/openfootball/euro.json/raw/master/$year$/euro.json'
20
+ }
21
+
22
+ ### note:
23
+ ## cache ALL methods - only do one web request for match schedule & results
24
+ def get_matches
25
+ @data ||= begin
26
+ str = APIS[ @league.downcase.to_sym ]
27
+ str = str.gsub( '$year$', @year.to_s )
28
+
29
+ get( str ) ## use "memoized" / cached result
30
+ end
31
+ end
32
+
33
+
34
+
35
+
36
+ ## for testing lets you use /round/1 etc.
37
+ def round( num )
38
+ h = get_matches
39
+ matches = h[ 'rounds' ][ num-1 ] ## note: rounds hash starts with zero (not 1)
40
+ matches
41
+ end
42
+
43
+
44
+ def todays_matches( date: Date.today ) matches_for( date ); end
45
+ def tomorrows_matches( date: Date.today ) matches_for( date+1 ); end
46
+ def yesterdays_matches( date: Date.today ) matches_for( date-1 ); end
47
+
48
+ def matches_for( date )
49
+ hash = get_matches
50
+ matches = select_matches( hash[ 'rounds' ] ) { |match| date == Date.parse( match['date'] ) }
51
+ matches
52
+ end
53
+
54
+
55
+ def upcoming_matches( date: Date.today )
56
+ ## note: includes todays matches for now
57
+ hash = get_matches
58
+ matches = select_matches( hash[ 'rounds' ] ) { |match| date <= Date.parse( match['date'] ) }
59
+ matches
60
+ end
61
+
62
+ def past_matches( date: Date.today )
63
+ hash = get_matches
64
+ matches = select_matches( hash[ 'rounds' ] ) { |match| date > Date.parse( match['date'] ) }
65
+ ## note reveserve matches (chronological order/last first)
66
+ matches.reverse
67
+ end
68
+
69
+ private
70
+
71
+ def select_matches( rounds )
72
+ matches = []
73
+ rounds.each do |round|
74
+ round['matches'].each do |match|
75
+ if yield( match )
76
+ ## hack: add (outer) round to match
77
+ match['round'] = round['name']
78
+ matches << match
79
+ else
80
+ ## puts " skipping game play_date #{play_date}"
81
+ end
82
+ end
83
+ end
84
+ matches
85
+ end
86
+
87
+
88
+ def get( str )
89
+ response = @worker.get_response( str )
90
+
91
+ if response.code == '200'
92
+ ##
93
+ ## fix/fix/todo/check:
94
+ ## do we need to force utf-8 encoding? yes!!!!
95
+ ## check for teams w/ non-ascii names
96
+ hash = JSON.parse( response.body )
97
+ ## pp hash
98
+ hash
99
+ else
100
+ logger.error "fetch HTTP - #{response.code} #{response.message}"
101
+ nil
102
+ end
103
+ end
104
+
105
+ end # class Client
106
+ end # module Footty
@@ -1,14 +1,14 @@
1
- # encoding: utf-8
2
-
3
-
4
- module Footty
5
- VERSION = '0.4.0'
6
-
7
- def self.banner
8
- "footty/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
9
- end
10
-
11
- def self.root
12
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
13
- end
14
- end
1
+
2
+ module Footty
3
+ VERSION = '0.4.1'
4
+
5
+ def self.banner
6
+ "footty/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
7
+ end
8
+
9
+ def self.root
10
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
11
+ end
12
+ end
13
+
14
+
@@ -0,0 +1,103 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_client_euro.rb
4
+
5
+ require 'helper'
6
+
7
+
8
+
9
+ class TestClientEuro < MiniTest::Test
10
+
11
+ def setup
12
+ @client = Footty::Client.new( league: 'euro', year: 2020 )
13
+ end
14
+
15
+
16
+ def test_getters
17
+ today = Date.new( 2021, 6, 15 )
18
+
19
+ todays = @client.todays_matches( date: today )
20
+ pp todays
21
+ assert_equal 2, todays.size
22
+
23
+ yesterdays = @client.yesterdays_matches( date: today )
24
+ pp yesterdays
25
+ assert_equal 3, yesterdays.size
26
+
27
+ tomorrows = @client.tomorrows_matches( date: today )
28
+ pp tomorrows
29
+ assert_equal 3, tomorrows.size
30
+
31
+ past = @client.past_matches( date: today )
32
+ pp past
33
+
34
+ upcoming = @client.upcoming_matches( date: today )
35
+ pp upcoming
36
+ end
37
+
38
+
39
+ def test_todays_matches_2021_6_15
40
+ today = Date.new( 2021, 6, 15 )
41
+ ary = @client.todays_matches( date: today )
42
+ pp ary
43
+ =begin
44
+ [{"num"=>31,
45
+ "date"=>"2021-06-15",
46
+ "team1"=>{"name"=>"Hungary", "code"=>"HUN"},
47
+ "team2"=>{"name"=>"Portugal", "code"=>"POR"},
48
+ "score1"=>nil,
49
+ "score2"=>nil,
50
+ "score1i"=>nil,
51
+ "score2i"=>nil,
52
+ "group"=>"Group F",
53
+ "round"=>"Matchday 1"},
54
+ ...
55
+ =end
56
+
57
+ assert_equal Array, ary.class ## for now just check return type (e.g. assume Array for parsed JSON data)
58
+ assert_equal 2, ary.size
59
+ assert_equal 'HUN', ary[0]['team1']['code']
60
+ assert_equal 'POR', ary[0]['team2']['code']
61
+ assert_equal 'Matchday 1', ary[0]['round']
62
+ # assert_equal 5, ary[0]['score1']
63
+ # assert_equal 0, ary[0]['score2']
64
+ end
65
+
66
+
67
+ def test_todays_matches_2021_6_10
68
+ today = Date.new( 2021, 6, 10 )
69
+ ary = @client.todays_matches( date: today )
70
+ ## note: returns empty array if no matches scheduled/playing today
71
+ pp ary
72
+
73
+ assert_equal Array, ary.class ## for now just check return type (e.g. assume Array for parsed JSON data)
74
+ assert ary.empty?
75
+ end
76
+
77
+
78
+ def test_euro_round_1
79
+ h = @client.round( 1 )
80
+
81
+ pp h
82
+ =begin
83
+ {"name"=>"Matchday 1",
84
+ "matches"=>
85
+ [{"num"=>1,
86
+ "date"=>"2021-06-11",
87
+ "team1"=>{"name"=>"Turkey", "code"=>"TUR"},
88
+ "team2"=>{"name"=>"Italy", "code"=>"ITA"},
89
+ "score1"=>0,
90
+ "score2"=>3,
91
+ "score1i"=>0,
92
+ "score2i"=>0,
93
+ "group"=>"Group A"},
94
+ =end
95
+
96
+ assert_equal 'TUR', h['matches'][0]['team1']['code']
97
+ assert_equal 'ITA', h['matches'][0]['team2']['code']
98
+ assert_equal 0, h['matches'][0]['score1']
99
+ assert_equal 3, h['matches'][0]['score2']
100
+ end
101
+
102
+
103
+ end # class TestClientEuro
@@ -1,36 +1,37 @@
1
- # encoding: utf-8
2
-
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_client_worldcup.rb
3
4
 
4
5
  require 'helper'
5
6
 
6
7
 
7
8
 
8
- class TestClient < MiniTest::Test
9
+ class TestClientWorldCup < MiniTest::Test
9
10
 
10
11
  def setup
11
- @client = Footty.client
12
+ @client = Footty::Client.new( league: 'worldcup', year: 2018 )
12
13
  end
13
14
 
14
15
 
15
16
  def test_getters
16
17
  today = Date.new( 2018, 6, 16 )
17
18
 
18
- todays = @client.get_todays_matches( date: today )
19
+ todays = @client.todays_matches( date: today )
19
20
  pp todays
20
21
  assert_equal 4, todays.size
21
22
 
22
- yesterdays = @client.get_yesterdays_matches( date: today )
23
+ yesterdays = @client.yesterdays_matches( date: today )
23
24
  pp yesterdays
24
25
  assert_equal 3, yesterdays.size
25
26
 
26
- tomorrows = @client.get_tomorrows_matches( date: today )
27
+ tomorrows = @client.tomorrows_matches( date: today )
27
28
  pp tomorrows
28
29
  assert_equal 3, tomorrows.size
29
30
 
30
- past = @client.get_past_matches( date: today )
31
+ past = @client.past_matches( date: today )
31
32
  pp past
32
33
 
33
- upcoming = @client.get_upcoming_matches( date: today )
34
+ upcoming = @client.upcoming_matches( date: today )
34
35
  pp upcoming
35
36
  end
36
37
 
@@ -38,7 +39,7 @@ class TestClient < MiniTest::Test
38
39
 
39
40
  def test_todays_matches_2018_6_14
40
41
  today = Date.new( 2018, 6, 14 )
41
- ary = @client.get_todays_matches( date: today )
42
+ ary = @client.todays_matches( date: today )
42
43
  ## pp ary
43
44
  =begin
44
45
  [{"num"=>1,
@@ -62,13 +63,13 @@ class TestClient < MiniTest::Test
62
63
  assert_equal 'RUS', ary[0]['team1']['code']
63
64
  assert_equal 'KSA', ary[0]['team2']['code']
64
65
  assert_equal 'Matchday 1', ary[0]['round']
65
- assert_nil ary[0]['score1']
66
- assert_nil ary[0]['score2']
66
+ assert_equal 5, ary[0]['score1']
67
+ assert_equal 0, ary[0]['score2']
67
68
  end
68
69
 
69
70
  def test_todays_matches_2018_6_10
70
71
  today = Date.new( 2018, 6, 10 )
71
- ary = @client.get_todays_matches( date: today )
72
+ ary = @client.todays_matches( date: today )
72
73
  ## note: returns empty array if no matches scheduled/playing today
73
74
  pp ary
74
75
 
@@ -77,7 +78,7 @@ class TestClient < MiniTest::Test
77
78
  end
78
79
 
79
80
  def test_world_2018_round_1
80
- h = @client.get_round( 1 )
81
+ h = @client.round( 1 )
81
82
 
82
83
  ## pp h
83
84
  =begin
@@ -100,13 +101,13 @@ class TestClient < MiniTest::Test
100
101
 
101
102
  assert_equal 'RUS', h['matches'][0]['team1']['code']
102
103
  assert_equal 'KSA', h['matches'][0]['team2']['code']
103
- assert_nil h['matches'][0]['score1']
104
- assert_nil h['matches'][0]['score2']
104
+ assert_equal 5, h['matches'][0]['score1']
105
+ assert_equal 0, h['matches'][0]['score2']
105
106
  end
106
107
 
107
108
 
108
109
  def test_world_2018_round_2
109
- h = @client.get_round( 2 )
110
+ h = @client.round( 2 )
110
111
 
111
112
  ## pp h
112
113
  =begin
@@ -155,9 +156,9 @@ class TestClient < MiniTest::Test
155
156
 
156
157
  assert_equal 'EGY', h['matches'][0]['team1']['code']
157
158
  assert_equal 'URU', h['matches'][0]['team2']['code']
158
- assert_nil h['matches'][0]['score1']
159
- assert_nil h['matches'][0]['score2']
159
+ assert_equal 0, h['matches'][0]['score1']
160
+ assert_equal 1, h['matches'][0]['score2']
160
161
  end
161
162
 
162
163
 
163
- end # class TestClient
164
+ end # class TestClientWorldCup
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-14 00:00:00.000000000 Z
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logutils
@@ -42,42 +42,48 @@ dependencies:
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
48
51
  type: :development
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
- - - "~>"
55
+ - - ">="
53
56
  - !ruby/object:Gem::Version
54
57
  version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: hoe
57
63
  requirement: !ruby/object:Gem::Requirement
58
64
  requirements:
59
65
  - - "~>"
60
66
  - !ruby/object:Gem::Version
61
- version: '3.16'
67
+ version: '3.22'
62
68
  type: :development
63
69
  prerelease: false
64
70
  version_requirements: !ruby/object:Gem::Requirement
65
71
  requirements:
66
72
  - - "~>"
67
73
  - !ruby/object:Gem::Version
68
- version: '3.16'
69
- description: footty - football.db command line client for world cup (russia 2018)
70
- and more - who is playing today?
74
+ version: '3.22'
75
+ description: footty - football.db command line client for european "euro" championship
76
+ 2020 (in 2021) and more - who is playing today?
71
77
  email: opensport@googlegroups.com
72
78
  executables:
73
79
  - footty
74
80
  extensions: []
75
81
  extra_rdoc_files:
76
- - HISTORY.md
82
+ - CHANGELOG.md
77
83
  - Manifest.txt
78
84
  - README.md
79
85
  files:
80
- - HISTORY.md
86
+ - CHANGELOG.md
81
87
  - Manifest.txt
82
88
  - README.md
83
89
  - Rakefile
@@ -86,12 +92,13 @@ files:
86
92
  - lib/footty/client.rb
87
93
  - lib/footty/version.rb
88
94
  - test/helper.rb
89
- - test/test_client.rb
95
+ - test/test_client_euro.rb
96
+ - test/test_client_worldcup.rb
90
97
  homepage: https://github.com/sportdb/footty
91
98
  licenses:
92
99
  - Public Domain
93
100
  metadata: {}
94
- post_install_message:
101
+ post_install_message:
95
102
  rdoc_options:
96
103
  - "--main"
97
104
  - README.md
@@ -108,10 +115,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
115
  - !ruby/object:Gem::Version
109
116
  version: '0'
110
117
  requirements: []
111
- rubyforge_project:
112
- rubygems_version: 2.5.2
113
- signing_key:
118
+ rubygems_version: 3.1.4
119
+ signing_key:
114
120
  specification_version: 4
115
- summary: footty - football.db command line client for world cup (russia 2018) and
116
- more - who is playing today?
121
+ summary: footty - football.db command line client for european "euro" championship
122
+ 2020 (in 2021) and more - who is playing today?
117
123
  test_files: []