footty 2024.5.10 → 2024.9.27

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
2
  SHA256:
3
- metadata.gz: 34ac44dbe56d51fad5a516b69331ab594243cbac79f5c4b63f69271455773cd5
4
- data.tar.gz: 428605f76f7713f3e61f8cf53cf80d5c8c3d6add43f649a0d701e9ca465d4259
3
+ metadata.gz: 2254b1fa1cf0832e403b6bc0e6509d1ffee06e0f552fec2b805b124c0a867c0d
4
+ data.tar.gz: 8c8182dabe0e72801b580e46bed8471baacd01080fedac360b2532b63673d9cb
5
5
  SHA512:
6
- metadata.gz: 359ab0cc33ca8b8482a1d2e9cb60ea58e96c95c5494dc35232018dba09fe164f22a8a167afc1536e90ed9dabb600fe412fab6d0c7aa1a4afa3e3967e3c857907
7
- data.tar.gz: 344366274d54e0721d8a718af983dd555009db88a8d11f89e56149bef17cb24ff23e17c772ca133a31bef0e0ac65a1dc68207b45e3c9a4c9c429241d30398599
6
+ metadata.gz: 3e7421b9f2bf8ec572a55075970301343604a4dbaaabfeceec10827df9a712184fa9372a72c34e0f79811a4ae47b8a773115916e0e195d46def89a9e509b509d
7
+ data.tar.gz: 4ef82377e9caead4e3ec0048b8eac6120fe77c8de4018e69e74faec2842f33909626234a5bc2ccef137661f999c7825f9ef834c64cab292bcf4e9c357467d645
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 2024.5.10
1
+ ### 2024.9.27
2
2
  ### 1.0.0 / 2018-06-09
3
3
 
4
4
  * Everything is new (again). First release.
data/Manifest.txt CHANGED
@@ -3,6 +3,7 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  bin/footty
6
+ bin/ftty
6
7
  lib/footty.rb
7
- lib/footty/client.rb
8
+ lib/footty/dataset.rb
8
9
  lib/footty/version.rb
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # footty - football.db command line client for european ("euro") championship 2024 and more
1
+ # footty - football.db command line tool for national & int'l football club leagues (& cups) from around the world (bonus - incl. world cup, euro and more)
2
+
2
3
 
3
4
  * home :: [github.com/sportdb/footty](https://github.com/sportdb/footty)
4
5
  * bugs :: [github.com/sportdb/footty/issues](https://github.com/sportdb/footty/issues)
@@ -11,15 +12,27 @@
11
12
 
12
13
  ## Usage - Who's playing today?
13
14
 
14
- The footty command line tool lets you query the online football.db HTTP JSON API services
15
+ The footty command line tool lets you query the online football.db via HTTP
15
16
  for upcoming or past matches. For example:
16
17
 
17
- $ footty # Defaults to today's euro 2024 matches
18
+ $ footty # Defaults to today's English Premier League 2024/25 matches
19
+
20
+ prints on Sep 27, 2024:
21
+
22
+ Upcoming matches:
23
+ Sat Sep/28 12:30 (in 1d) Newcastle United FC vs Manchester City FC Matchday 6
24
+ Sat Sep/28 15:00 (in 1d) Arsenal FC vs Leicester City FC Matchday 6
25
+ Sat Sep/28 15:00 (in 1d) Brentford FC vs West Ham United FC Matchday 6
26
+ Sat Sep/28 15:00 (in 1d) Chelsea FC vs Brighton & Hove Albion Matchday 6
27
+ Sat Sep/28 15:00 (in 1d) Everton FC vs Crystal Palace FC Matchday 6
28
+ Sat Sep/28 15:00 (in 1d) Nottingham Forest FC vs Fulham FC Matchday 6
29
+ Sat Sep/28 17:30 (in 1d) Wolverhampton Wanderers FC vs Liverpool FC Matchday 6
30
+ Sun Sep/29 14:00 (in 2d) Ipswich Town FC vs Aston Villa FC Matchday 6
31
+ Sun Sep/29 16:30 (in 2d) Manchester United FC vs Tottenham Hotspur FC Matchday 6
32
+ Mon Sep/30 20:00 (in 3d) AFC Bournemouth vs Southampton FC Matchday 6
33
+
18
34
 
19
- prints on Jun/14 2024:
20
35
 
21
- #1 Fri Jun/14 Germany (GER) vs Scotland (SCO) Group A / Matchday 1
22
-
23
36
  Use `tomorrow` or `t` or `+1` to print tomorrow's matches e.g.:
24
37
 
25
38
  $ footty tomorrow # -or-
@@ -41,9 +54,34 @@ Use `past` or `p` to print all past matches e.g.:
41
54
  $ footty p
42
55
 
43
56
 
57
+
44
58
  That's it. Enjoy the beautiful game.
45
59
 
46
60
 
61
+ ## Bonus - More Leagues & Cups - Bundesliga, Serie A, Ligue 1, La Liga & More
62
+
63
+ Pass in the league code to display the Germand Bundesliga, Spanish La Liga, etc:
64
+
65
+ $ footty de # who's playing in the bundesliga today?
66
+ $ footty es # who's playing in la liga today?
67
+ ...
68
+
69
+ League codes include:
70
+
71
+ - `de` => Bundesliga
72
+ - `es` => La Liga
73
+ - `it` => Serie A
74
+ - `fr` => Ligue 1
75
+ - ...
76
+
77
+ More
78
+
79
+ - `world` => World Cup
80
+ - `euro` => "Euro" - European Championship
81
+
82
+ See [footty/dataset](https://github.com/sportdb/footty/blob/master/lib/footty/dataset.rb) for the complete built-in list of data sources (and league keys).
83
+
84
+
47
85
 
48
86
 
49
87
  ## Trivia
@@ -66,7 +104,6 @@ Use it as you please with no restrictions whatsoever.
66
104
 
67
105
 
68
106
 
69
-
70
107
  ## Questions? Comments?
71
108
 
72
109
  Yes, you can. More than welcome.
data/Rakefile CHANGED
@@ -2,29 +2,28 @@ require 'hoe'
2
2
  require './lib/footty/version.rb'
3
3
 
4
4
  Hoe.spec 'footty' do
5
-
6
5
  self.version = Footty::VERSION
7
6
 
8
- self.summary = 'footty - football.db command line client for european "euro" championship 2024 and more - who is playing today?'
7
+ self.summary = "footty - football.db command line tool for national & int'l football club leagues (& cups) from around the world (bonus - incl. world cup, euro and more)"
9
8
  self.description = summary
10
9
 
11
10
  self.urls = { home: 'https://github.com/sportdb/footty' }
12
11
 
13
12
  self.author = 'Gerald Bauer'
14
- self.email = 'opensport@googlegroups.com'
13
+ self.email = 'gerald.bauer@gmail.com'
15
14
 
16
15
  # switch extension to .markdown for gihub formatting
17
16
  self.readme_file = 'README.md'
18
17
  self.history_file = 'CHANGELOG.md'
19
18
 
20
19
  self.extra_deps = [
21
- ['logutils' ],
22
- ['fetcher']
20
+ ['sportdb-quick', '>= 0.2.0'],
21
+ ['webget'],
23
22
  ]
24
23
 
25
24
  self.licenses = ['Public Domain']
26
25
 
27
26
  self.spec_extras = {
28
- required_ruby_version: '>= 2.3'
27
+ required_ruby_version: '>= 3.1.0'
29
28
  }
30
29
  end
data/bin/ftty ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## tip: to test run:
4
+ ## ruby -I ./lib bin/ftty
5
+
6
+ require 'footty'
7
+
8
+ Footty.main
@@ -0,0 +1,189 @@
1
+ module Footty
2
+
3
+
4
+ class Dataset
5
+ SOURCES = {
6
+ 'world' => { '2022' => [ 'worldcup/2022--qatar/cup.txt',
7
+ 'worldcup/2022--qatar/cup_finals.txt'],
8
+ '2018' => [ 'worldcup/2018--russia/cup.txt',
9
+ 'worldcup/2018--russia/cup_finals.txt']
10
+ },
11
+ 'euro' => { '2024' => 'euro/2024--germany/euro.txt',
12
+ '2021' => 'euro/2021--europe/euro.txt'
13
+ },
14
+ 'de' => 'deutschland/$season$/1-bundesliga.txt',
15
+ 'de2' => 'deutschland/$season$/2-bundesliga2.txt',
16
+ 'en'=> 'england/$season$/1-premierleague.txt',
17
+ 'es'=> 'espana/$season$/1-liga.txt',
18
+ 'it'=> 'italy/$season$/1-seriea.txt',
19
+ 'at'=> 'austria/$season$/1-bundesliga.txt',
20
+ 'at2' => 'austria/$season$/2-liga2.txt',
21
+ 'at3o' => 'austria/$season$/3-regionalliga-ost.txt',
22
+ 'atcup' => 'austria/$season$/cup.txt',
23
+
24
+ 'fr'=> 'europe/france/$season$/1-ligue1.txt',
25
+ 'nl'=> 'europe/netherlands/$season$/1-eredivisie.txt',
26
+ 'be'=> 'europe/belgium/$season$/1-firstdivisiona.txt',
27
+
28
+ 'champs'=> 'champions-league/$season$/cl.txt',
29
+
30
+ 'br' => 'south-america/brazil/$year$/1-seriea.txt',
31
+ 'ar' => 'south-america/argentina/$year$/1-primeradivision.txt',
32
+ 'co' => 'south-america/colombia/$year$/1-primeraa.txt',
33
+ ## use a different code for copa libertadores? why? why not?
34
+ 'copa' => 'south-america/copa-libertadores/$year$/libertadores.txt',
35
+
36
+ 'mx' => 'mexico/$season$/1-ligamx.txt',
37
+
38
+ 'eg' => 'africa/egypt/$season$/1-premiership.txt',
39
+ 'ma' => 'africa/morocco/$season$/1-botolapro1.txt',
40
+ }
41
+
42
+
43
+ ## return built-in league keys
44
+ def self.leagues() SOURCES.keys; end
45
+
46
+
47
+ def initialize( league:, year: nil )
48
+ @league = league
49
+
50
+ spec = SOURCES[ @league.downcase ]
51
+ urls = if spec.is_a?( Hash ) ## assume lookup by year
52
+ if year.nil? ## lookup default first entry
53
+ year = spec.keys[0].to_i
54
+ spec.values[0]
55
+ else
56
+ spec[ year.to_s ]
57
+ end
58
+ else ## assume vanilla urls (no lookup by year)
59
+ ## default to 2024 for now
60
+ year = 2024 if year.nil?
61
+ spec
62
+ end
63
+ raise ArgumentError, "no dataset (source) for league #{league} found" if urls.nil?
64
+
65
+ ## wrap single sources (strings) in array
66
+ urls = urls.is_a?( Array ) ? urls : [urls]
67
+ ## expand shortened url and fill-in template vars
68
+ @urls = urls.map { |url| openfootball_url( url, year: year ) }
69
+ end
70
+
71
+
72
+ def openfootball_url( path, year: )
73
+ repo, local_path = path.split( '/', 2)
74
+ url = "https://raw.githubusercontent.com/openfootball/#{repo}/master/#{local_path}"
75
+ ## check for template vars too
76
+ season = Season( "#{year}/#{year+1}" )
77
+ url = url.gsub( '$year$', year.to_s )
78
+ url = url.gsub( '$season$', season.to_path )
79
+ url
80
+ end
81
+
82
+
83
+ ### note:
84
+ ## cache ALL methods - only do one web request for match schedule & results
85
+ def matches
86
+ @data ||= begin
87
+ matches = []
88
+ @urls.each do |url|
89
+ txt = get!( url ) ## use "memoized" / cached result
90
+ matches += SportDb::QuickMatchReader.parse( txt )
91
+ end
92
+ data = matches.map {|match| match.as_json } # convert to json
93
+ ## quick hack to get keys as strings not symbols!!
94
+ ## fix upstream
95
+ JSON.parse( JSON.generate( data ))
96
+ end
97
+ end
98
+
99
+
100
+ def end_date
101
+ @end_date ||= begin
102
+ end_date = nil
103
+ matches.each do |match|
104
+ date = Date.strptime(match['date'], '%Y-%m-%d' )
105
+ end_date = date if end_date.nil? ||
106
+ date > end_date
107
+ end
108
+ end_date
109
+ end
110
+ end
111
+
112
+ def start_date
113
+ @start_date ||= begin
114
+ start_date = nil
115
+ matches.each do |match|
116
+ date = Date.strptime(match['date'], '%Y-%m-%d' )
117
+ start_date = date if start_date.nil? ||
118
+ date < start_date
119
+ end
120
+ start_date
121
+ end
122
+ end
123
+
124
+ def todays_matches( date: Date.today ) matches_for( date ); end
125
+ def tomorrows_matches( date: Date.today ) matches_for( date+1 ); end
126
+ def yesterdays_matches( date: Date.today ) matches_for( date-1 ); end
127
+
128
+ def matches_for( date )
129
+ matches = select_matches { |match| date == Date.parse( match['date'] ) }
130
+ matches
131
+ end
132
+
133
+
134
+ def upcoming_matches( date: Date.today,
135
+ limit: nil )
136
+ ## note: includes todays matches for now
137
+ matches = select_matches { |match| date <= Date.parse( match['date'] ) }
138
+
139
+ if limit
140
+ matches[0, limit] ## cut-off
141
+ else
142
+ matches
143
+ end
144
+ end
145
+
146
+ def past_matches( date: Date.today )
147
+ matches = select_matches { |match| date > Date.parse( match['date'] ) }
148
+ ## note reveserve matches (chronological order/last first)
149
+ ## matches.reverse
150
+ matches
151
+ end
152
+
153
+
154
+ private
155
+ def select_matches( &blk)
156
+ selected = []
157
+ matches.each do |match|
158
+ selected << match if blk.call( match )
159
+ end
160
+
161
+ ## todo/fix:
162
+ ## sort matches here; might not be chronologicial (by default)
163
+ selected
164
+ end # method select_matches
165
+
166
+
167
+
168
+ def get!( url )
169
+ ## use cached urls for 12h by default
170
+ ## if expired in cache (or not present) than get/fetch
171
+ if Webcache.expired_in_12h?( url )
172
+ response = Webget.text( url )
173
+
174
+ if response.status.ok?
175
+ response.text # note - return text (utf-8)
176
+ else
177
+ ## dump headers
178
+ response.headers.each do |key,value|
179
+ puts " #{key}: #{value}"
180
+ end
181
+ puts "!! HTTP ERROR - #{response.status.code} #{response.status.message}"
182
+ exit 1
183
+ end
184
+ else
185
+ Webcache.read( url )
186
+ end
187
+ end # method get_txt!
188
+ end # class Dataset
189
+ end # module Footty
@@ -1,6 +1,6 @@
1
1
 
2
2
  module Footty
3
- VERSION = '2024.5.10'
3
+ VERSION = '2024.9.27'
4
4
 
5
5
  def self.banner
6
6
  "footty/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
data/lib/footty.rb CHANGED
@@ -1,63 +1,75 @@
1
- ## stdlibs
1
+ require 'sportdb/quick' ## note - pulls in cocos et al
2
+ require 'webget' ## add webcache support
2
3
 
3
- require 'net/http'
4
- require 'uri'
5
- require 'json'
6
- require 'pp'
7
-
8
-
9
- ## 3rd party gems/libs
10
- ## require 'props'
4
+ # our own code
5
+ require_relative 'footty/version' # let it always go first
6
+ require_relative 'footty/dataset'
11
7
 
12
- require 'logutils'
13
- require 'fetcher'
14
8
 
15
9
 
16
- # our own code
17
- require 'footty/version' # let it always go first
18
- require 'footty/client'
10
+ ## set cache to local .cache dir for now - why? why not?
11
+ Webcache.root = './cache'
12
+ # pp Webcache.root
13
+ Webget.config.sleep = 1 ## set delay in secs (to 1 sec - default is/maybe 3)
19
14
 
20
15
 
21
16
  module Footty
17
+ def self.main( args=ARGV )
18
+ puts banner # say hello
22
19
 
23
- def self.client
24
- ## note: hard code tournament / league for now
25
- @client ||= Client.new( league: 'euro', year: 2024 ) ## use "singelton" / shared client
26
- end
20
+ league = 'en'
21
+ year = nil
27
22
 
23
+ leagues = Dataset.leagues ## e.g. ['world','euro',
24
+ ## 'de','en','at']
28
25
 
26
+ ## filter args for league or year
27
+ args = args.select do |arg|
28
+ if arg =~ /^\d{4}$/
29
+ year = arg.to_i(10)
30
+ false ## eat-up
31
+ elsif leagues.include?( arg )
32
+ league = arg
33
+ false
34
+ else
35
+ true
36
+ end
37
+ end
29
38
 
30
- def self.main
31
- puts banner # say hello
32
39
 
33
- what = ARGV[0] || 'today'
40
+ what = args[0] || 'today'
34
41
  what = what.downcase
35
42
 
43
+
44
+ # Dataset.new( league: 'euro', year: 2024 )
45
+ dataset = Dataset.new( league: league, year: year )
46
+
47
+
36
48
  ## in the future make today "configurable" as param - why? why not?
37
49
  today = Date.today
38
50
 
39
51
  if ['yesterday', 'y', '-1'].include?( what )
40
- matches = client.yesterdays_matches
52
+ matches = dataset.yesterdays_matches
41
53
  if matches.empty?
42
54
  puts "** No matches played yesterday.\n"
43
55
  end
44
56
  elsif ['tomorrow', 't', '+1', '1'].include?( what )
45
- matches = client.tomorrows_matches
57
+ matches = dataset.tomorrows_matches
46
58
  if matches.empty?
47
59
  puts "** No matches scheduled tomorrow.\n"
48
60
  end
49
61
  elsif ['past', 'p', 'prev'].include?( what )
50
- matches = client.past_matches
62
+ matches = dataset.past_matches
51
63
  if matches.empty?
52
64
  puts "** No matches played yet.\n"
53
65
  end
54
66
  elsif ['upcoming', 'up', 'u', 'next', 'n'].include?( what )
55
- matches = client.upcoming_matches
67
+ matches = dataset.upcoming_matches
56
68
  if matches.empty?
57
69
  puts "** No more matches scheduled.\n"
58
70
  end
59
71
  else
60
- matches = client.todays_matches
72
+ matches = dataset.todays_matches
61
73
 
62
74
  ## no matches today
63
75
  if matches.empty?
@@ -65,50 +77,71 @@ module Footty
65
77
 
66
78
  ## note: was world cup 2018 - end date -- Date.new( 2018, 7, 11 )
67
79
  ## note: was euro 2020 (in 2021) - end date -- Date.new( 2021, 7, 11 )
68
- if Date.today > Date.new( 2024, 7, 14 ) ## tournament is over, look back
80
+ if Date.today > dataset.end_date ## tournament is over, look back
69
81
  puts "Past matches:"
70
- matches = client.past_matches
82
+ matches = dataset.past_matches
71
83
  else ## world cup is upcoming /in-progress,look forward
72
84
  puts "Upcoming matches:"
73
- matches = client.upcoming_matches
85
+ matches = dataset.upcoming_matches( limit: 18 )
74
86
  end
75
87
  end
76
88
  end
77
89
 
78
-
79
-
80
90
  print_matches( matches )
81
91
  end
82
92
 
83
93
 
84
-
85
94
  def self.print_matches( matches )
86
95
  ## print games
87
96
 
88
97
  today = Date.today
89
98
 
90
99
  matches.each do |match|
91
- print " %5s" % "\##{match['num']} "
100
+ print " %5s" % "\##{match['num']} " if match['num']
92
101
 
93
- date = Date.parse( match['date'] )
102
+ date = Date.strptime( match['date'], '%Y-%m-%d' )
94
103
  print "#{date.strftime('%a %b/%d')} " ## e.g. Thu Jun/14
104
+ print "#{match['time']} " if match['time']
105
+
95
106
  if date > today
96
107
  diff = (date - today).to_i
97
108
  print "%10s" % "(in #{diff}d) "
98
109
  end
99
110
 
100
- print "%22s" % "#{match['team1']['name']} (#{match['team1']['code']})"
101
111
 
102
- ## todo/fix: add support for knockout scores
103
- ## with score1et/score1p (extra time and penalty)
104
- if match['score1'] && match['score2']
112
+ if match['team1'].is_a?( Hash )
113
+ print "%22s" % "#{match['team1']['name']} (#{match['team1']['code']})"
114
+ else
115
+ print "%22s" % "#{match['team1']}"
116
+ end
117
+
118
+
119
+ if match['score'].is_a?( Hash ) &&
120
+ match['score']['ft']
121
+ if match['score']['ft']
122
+ print " #{match['score']['ft'][0]}-#{match['score']['ft'][1]} "
123
+ end
124
+ if match['score']['et']
125
+ print "aet #{match['score']['et'][0]}-#{match['score']['et'][1]} "
126
+ end
127
+ if match['score']['p']
128
+ print "pen #{match['score']['p'][0]}-#{match['score']['p'][1]} "
129
+ end
130
+ elsif match['score1'] && match['score2']
131
+ ## todo/fix: add support for knockout scores
132
+ ## with score1et/score1p (extra time and penalty)
105
133
  print " #{match['score1']}-#{match['score2']} "
106
134
  print "(#{match['score1i']}-#{match['score2i']}) "
107
135
  else
108
136
  print " vs "
109
137
  end
110
138
 
111
- print "%-22s" % "#{match['team2']['name']} (#{match['team2']['code']})"
139
+ if match['team2'].is_a?( Hash )
140
+ print "%-22s" % "#{match['team2']['name']} (#{match['team2']['code']})"
141
+ else
142
+ print "%-22s" % "#{match['team2']}"
143
+ end
144
+
112
145
 
113
146
  if match['group']
114
147
  print " #{match['group']} /" ## group phase/stage
@@ -149,8 +182,6 @@ module Footty
149
182
  end
150
183
  print "]\n"
151
184
  end
152
-
153
-
154
185
  end
155
186
  end
156
187
 
metadata CHANGED
@@ -1,31 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footty
3
3
  version: !ruby/object:Gem::Version
4
- version: 2024.5.10
4
+ version: 2024.9.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-10 00:00:00.000000000 Z
11
+ date: 2024-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: logutils
14
+ name: sportdb-quick
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: fetcher
28
+ name: webget
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -72,11 +72,12 @@ dependencies:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '4.1'
75
- description: footty - football.db command line client for european "euro" championship
76
- 2024 and more - who is playing today?
77
- email: opensport@googlegroups.com
75
+ description: footty - football.db command line tool for national & int'l football
76
+ club leagues (& cups) from around the world (bonus - incl. world cup, euro and more)
77
+ email: gerald.bauer@gmail.com
78
78
  executables:
79
79
  - footty
80
+ - ftty
80
81
  extensions: []
81
82
  extra_rdoc_files:
82
83
  - CHANGELOG.md
@@ -88,8 +89,9 @@ files:
88
89
  - README.md
89
90
  - Rakefile
90
91
  - bin/footty
92
+ - bin/ftty
91
93
  - lib/footty.rb
92
- - lib/footty/client.rb
94
+ - lib/footty/dataset.rb
93
95
  - lib/footty/version.rb
94
96
  homepage: https://github.com/sportdb/footty
95
97
  licenses:
@@ -105,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
105
107
  requirements:
106
108
  - - ">="
107
109
  - !ruby/object:Gem::Version
108
- version: '2.3'
110
+ version: 3.1.0
109
111
  required_rubygems_version: !ruby/object:Gem::Requirement
110
112
  requirements:
111
113
  - - ">="
@@ -115,6 +117,6 @@ requirements: []
115
117
  rubygems_version: 3.4.10
116
118
  signing_key:
117
119
  specification_version: 4
118
- summary: footty - football.db command line client for european "euro" championship
119
- 2024 and more - who is playing today?
120
+ summary: footty - football.db command line tool for national & int'l football club
121
+ leagues (& cups) from around the world (bonus - incl. world cup, euro and more)
120
122
  test_files: []
data/lib/footty/client.rb DELETED
@@ -1,106 +0,0 @@
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