footballdata-api 0.4.2 → 0.4.4

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: 97e75a5cbf4b952cb018a40c4ff790a201c26cbd95af1027bae3e7ac2153d1b5
4
- data.tar.gz: a4d0cfd2e6ff636f030cd6c4d4d949f2173763cc39352b28b3425ad9aa077796
3
+ metadata.gz: b5bd4d077f49907b80638105f2152e677540431fee3cee6b9022c48c8a3daadd
4
+ data.tar.gz: fa80a496acc7e4d3bc2a4095543716c56cf5497b27b994dd173a468ba220b041
5
5
  SHA512:
6
- metadata.gz: d1c8650effbb80caec23410ee3fc739f379976359f044b29eff3a02d7bd82f23d76f7daffd6b2cfa76dfbdcbc6be53e178a04929b02401a30641f29cb3d0bd18
7
- data.tar.gz: 39d810683288fc35703f19fd1643af8bb0b8332168ae4d4e819eb681444ea4c27e7c0b36daccf27fc97d02704aa6325696579a6d5b3941988cd6bef8f400d0ec
6
+ metadata.gz: 51c7867e5767815a885c9ea7c45df6ae8305bcc74ac8d377ac96de8be9c9577441b5d5fb9c88d40f53af7b0ca1798673cf4c07149291dc6daaa53dd5632be384
7
+ data.tar.gz: 25a7b9227fe453551d5f76b9a1f0f09c255ffa75e6f3aaa36f7ad5791130ecd42474b0da8c1b5f2f11c915665e601c8749a1ae1ce5efa6920d935d32a403bef7
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.4.2
1
+ ### 0.4.4
2
2
 
3
3
  ### 0.0.1 / 2024-07-03
4
4
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # footballdata-api - get football data via Daniel Freitag's football-data.org api v4
1
+ # footballdata-api - get football data via Daniel Freitag's football-data.org api v4
2
2
 
3
3
 
4
4
  * home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
@@ -48,14 +48,13 @@ Footballdata.schedule( league: 'eng.2', season: '2020/21' )
48
48
 
49
49
  Footballdata.schedule( league: 'de.1', season: '2020/21' )
50
50
  Footballdata.schedule( league: 'es.1', season: '2020/21' )
51
-
52
51
  Footballdata.schedule( league: 'fr.1', season: '2020/21' )
53
52
  Footballdata.schedule( league: 'it.1', season: '2020/21' )
54
53
 
55
54
  Footballdata.schedule( league: 'nl.1', season: '2020/21' )
56
55
  Footballdata.schedule( league: 'pt.1', season: '2020/21' )
57
56
 
58
- Footballdata.schedule( league: 'cl', season: '2020/21' )
57
+ Footballdata.schedule( league: 'uefa.cl', season: '2020/21' )
59
58
 
60
59
  # note: Brasileirão - season is a calendar year (NOT an academic year)
61
60
  Footballdata.schedule( league: 'br.1', season: '2020' )
@@ -83,7 +82,7 @@ require 'footballdata'
83
82
  'it.1',
84
83
  'nl.1',
85
84
  'pt.1',
86
- 'cl',
85
+ 'uefa.cl',
87
86
  ].each do |league|
88
87
  Footballdata.convert( league: league, season: '2020/21' )
89
88
  end
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ Hoe.spec 'footballdata-api' do
19
19
 
20
20
  self.extra_deps = [
21
21
  ['football-timezones'],
22
+ ['fifa'],
22
23
  ['webget'],
23
24
  ]
24
25
 
@@ -3,6 +3,8 @@ module Footballdata
3
3
 
4
4
  #######
5
5
  ## map round-like to higher-level stages
6
+ ## fix - map by league codes
7
+ ## or * (all)
6
8
  STAGES = {
7
9
  'REGULAR_SEASON' => ['Regular'],
8
10
 
@@ -37,6 +39,30 @@ STAGES = {
37
39
 
38
40
 
39
41
 
42
+
43
+ def self.find_team_country_code( name, teams: )
44
+ ## add (fifa) country code e.g.
45
+ ## Liverpool FC => Liverpool FC (ENG)
46
+ ## or Liverpool FC => Liverpool FC (URU)
47
+ rec = teams[ name ]
48
+ if rec.nil?
49
+ puts "!! ERROR - no team record found in teams.json for #{name}"
50
+ pp teams.keys
51
+ exit 1
52
+ end
53
+
54
+ country_name = rec['area']['name']
55
+ country = Fifa.world.find_by_name( country_name )
56
+ if country.nil?
57
+ puts "!! ERROR - no country record found for #{country_name}"
58
+ exit 1
59
+ end
60
+
61
+ country.code
62
+ end
63
+
64
+
65
+
40
66
  def self.convert( league:, season: )
41
67
 
42
68
  season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
@@ -50,6 +76,14 @@ def self.convert( league:, season: )
50
76
  data_teams = Webcache.read_json( teams_url )
51
77
 
52
78
 
79
+ ## note - for internation club tournaments
80
+ ## auto-add (fifa) country code e.g.
81
+ ## Liverpool FC => Liverpool FC (ENG)
82
+ ##
83
+ ## todo/fix - move flag to league_info via .csv config - why? why not?
84
+ clubs_intl = ['uefa.cl',
85
+ 'copa.l'].include?(league.downcase) ? true : false
86
+
53
87
 
54
88
  ## check for time zone
55
89
  tz = find_zone!( league: league,
@@ -94,10 +128,17 @@ matches.each do |m|
94
128
  team1 = m['homeTeam']['name'] || 'N.N.'
95
129
  team2 = m['awayTeam']['name'] || 'N.N.'
96
130
 
97
- score = m['score']
131
+ ## auto-fix copa.l 2024
132
+ ## !! ERROR: unsupported match status >IN_PLAY< - sorry:
133
+ if m['status'] == 'IN_PLAY' &&
134
+ team1 == 'Club Aurora' && team2 == 'FBC Melgar'
135
+ m['status'] = 'FINISHED'
136
+ end
98
137
 
99
138
 
100
139
 
140
+ score = m['score']
141
+
101
142
  group = m['group']
102
143
  ## GROUP_A
103
144
  ## shorten group to A|B|C etc.
@@ -151,8 +192,9 @@ matches.each do |m|
151
192
  end
152
193
 
153
194
 
154
- teams[ team1 ] += 1
155
- teams[ team2 ] += 1
195
+ teams[ team1 ] += 1
196
+ teams[ team2 ] += 1
197
+
156
198
 
157
199
  ### mods - rename club names
158
200
  unless mods.nil? || mods.empty?
@@ -160,13 +202,22 @@ matches.each do |m|
160
202
  team2 = mods[ team2 ] if mods[ team2 ]
161
203
  end
162
204
 
205
+ ####
206
+ # auto-add (fifa) country code if int'l club tournament
207
+ if clubs_intl
208
+ ## note - use "original" name (not moded) for lookup
209
+ team1_org = m['homeTeam']['name']
210
+ team2_org = m['awayTeam']['name']
211
+ if team1_org ## note - ignore no team/placeholder (e.g. N.N)
212
+ country_code = find_team_country_code( team1_org, teams: teams_by_name )
213
+ team1 = "#{team1} (#{country_code})"
214
+ end
215
+ if team2_org ## note - ignore no team/placeholder (e.g. N.N)
216
+ country_code = find_team_country_code( team2_org, teams: teams_by_name )
217
+ team2 = "#{team2} (#{country_code})"
218
+ end
219
+ end
163
220
 
164
- ## auto-fix copa.l 2024
165
- ## !! ERROR: unsupported match status >IN_PLAY< - sorry:
166
- if m['status'] == 'IN_PLAY' &&
167
- team1 == 'Club Aurora' && team2 == 'FBC Melgar'
168
- m['status'] = 'FINISHED'
169
- end
170
221
 
171
222
 
172
223
  comments = ''
@@ -178,7 +229,7 @@ matches.each do |m|
178
229
  stats['status'][m['status']] += 1 ## track status counts
179
230
 
180
231
  case m['status']
181
- when 'SCHEDULED', 'TIMED' ## , 'IN_PLAY'
232
+ when 'SCHEDULED', 'TIMED' ## , 'IN_PLAY', 'PAUSED'
182
233
  ft = ''
183
234
  ht = ''
184
235
  when 'FINISHED'
@@ -12,6 +12,9 @@ module Footballdata
12
12
  'br.1' => {
13
13
  'América FC' => 'América Mineiro', # in year 2018 ??
14
14
  },
15
+ 'copa.l' => {
16
+ 'América FC' => 'América Mineiro', # in year 2022
17
+ },
15
18
  'pt.1' => {
16
19
  'Vitória SC' => 'Vitória Guimarães', ## avoid easy confusion with Vitória SC <=> Vitória FC
17
20
  'Vitória FC' => 'Vitória Setúbal',
@@ -2,7 +2,7 @@
2
2
  module FootballdataApi
3
3
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
4
  MINOR = 4
5
- PATCH = 2
5
+ PATCH = 4
6
6
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
7
 
8
8
  def self.version
data/lib/footballdata.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  ## 3rd party (our own)
2
2
  require 'football/timezones' # note - pulls in season/formats, cocos & tzinfo
3
3
  require 'webget' ## incl. webget, webcache, webclient, etc.
4
+ require 'fifa'
4
5
 
5
6
 
6
7
  module Footballdata
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: footballdata-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.4.4
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-09-15 00:00:00.000000000 Z
11
+ date: 2024-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: football-timezones
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: fifa
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: webget
29
43
  requirement: !ruby/object:Gem::Requirement