footballdata-api 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +3 -0
- data/bin/fbdat +3 -10
- data/config/leagues.csv +54 -0
- data/config/timezones.csv +27 -0
- data/lib/footballdata/convert.rb +22 -47
- data/lib/footballdata/download.rb +11 -11
- data/lib/footballdata/leagues.rb +20 -55
- data/lib/footballdata/teams.rb +13 -14
- data/lib/footballdata/timezones.rb +97 -0
- data/lib/footballdata/version.rb +1 -1
- data/lib/footballdata.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b3350fb47d596e6d5b2e4d73582b2615020d56db38cf86d9545a10b1760494c1
|
4
|
+
data.tar.gz: d7ba6c51f3e12beed59df7b851e8d533a838de67e73c5b1d025ab7a1256caa7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2943bcf6f2da49dfc1cab26da0933957d2bde2fb13749c7ce4d4896214484bac3edcea197e01ed9b2b63f92e2e74f560ac49189f63be7644522b7b24b7cbed73
|
7
|
+
data.tar.gz: 945cc2d0cb9346434c6f3875c33dd153867318b73e067c5574bc6e789f7b3b293d5c7f126c80221c676998eaa0e532647b7a25b960d082097209b6a1428f879e
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -3,6 +3,8 @@ Manifest.txt
|
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
5
|
bin/fbdat
|
6
|
+
config/leagues.csv
|
7
|
+
config/timezones.csv
|
6
8
|
lib/footballdata.rb
|
7
9
|
lib/footballdata/convert.rb
|
8
10
|
lib/footballdata/download.rb
|
@@ -11,4 +13,5 @@ lib/footballdata/mods.rb
|
|
11
13
|
lib/footballdata/prettyprint.rb
|
12
14
|
lib/footballdata/stat.rb
|
13
15
|
lib/footballdata/teams.rb
|
16
|
+
lib/footballdata/timezones.rb
|
14
17
|
lib/footballdata/version.rb
|
data/bin/fbdat
CHANGED
@@ -166,19 +166,12 @@ end
|
|
166
166
|
## note - only use "generic" uniform league codes for now!!
|
167
167
|
|
168
168
|
league_code = (args[0] || 'eng.1').downcase
|
169
|
-
metal_league_code = nil ## todo - find a better name
|
170
|
-
## use internal_league_code or such - why? why not?
|
171
169
|
|
170
|
+
## todo - find a better name
|
171
|
+
## use internal_league_code or such - why? why not?
|
172
172
|
### convenience helpers - lets you use eng.1, euro, etc.
|
173
173
|
## check if mapping for league_code
|
174
|
-
|
175
|
-
metal_league_code = LEAGUES[ league_code ]
|
176
|
-
else
|
177
|
-
puts "!! ERROR - no code/mapping found for league >#{league_code}<"
|
178
|
-
puts " mappings include:"
|
179
|
-
pp LEAGUES
|
180
|
-
exit 1
|
181
|
-
end
|
174
|
+
metal_league_code = find_league!( league_code )
|
182
175
|
|
183
176
|
|
184
177
|
season = Season( args[1] ||
|
data/config/leagues.csv
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
key, code
|
2
|
+
|
3
|
+
eng.1, PL # incl. team(s) from wales
|
4
|
+
eng.2, ELC
|
5
|
+
# PL - Premier League, England 27 seasons | 2019-08-09 - 2020-07-25 / matchday 31
|
6
|
+
# ELC - Championship, England 3 seasons | 2019-08-02 - 2020-07-22 / matchday 38
|
7
|
+
#
|
8
|
+
# 2019 => 2019/20
|
9
|
+
# 2018 => 2018/19
|
10
|
+
# 2017 => xxx 2017-18 - requires subscription !!!
|
11
|
+
|
12
|
+
es.1, PD
|
13
|
+
# PD - Primera Division, Spain 27 seasons | 2019-08-16 - 2020-07-19 / matchday 31
|
14
|
+
|
15
|
+
pt.1, PPL
|
16
|
+
# PPL - Primeira Liga, Portugal 9 seasons | 2019-08-10 - 2020-07-26 / matchday 28
|
17
|
+
|
18
|
+
de.1, BL1
|
19
|
+
# BL1 - Bundesliga, Germany 24 seasons | 2019-08-16 - 2020-06-27 / matchday 34
|
20
|
+
|
21
|
+
nl.1, DED
|
22
|
+
# DED - Eredivisie, Netherlands 10 seasons | 2019-08-09 - 2020-03-08 / matchday 34
|
23
|
+
|
24
|
+
fr.1, FL1 # incl. team(s) monaco
|
25
|
+
# FL1 - Ligue 1, France
|
26
|
+
# 9 seasons | 2019-08-09 - 2020-05-31 / matchday 38
|
27
|
+
#
|
28
|
+
# 2019 => 2019/20
|
29
|
+
# 2018 => 2018/19
|
30
|
+
# 2017 => xxx 2017-18 - requires subscription !!!
|
31
|
+
|
32
|
+
it.1, SA
|
33
|
+
# SA - Serie A, Italy 15 seasons | 2019-08-24 - 2020-08-02 / matchday 27
|
34
|
+
|
35
|
+
br.1, BSA
|
36
|
+
# BSA - Série A, Brazil
|
37
|
+
# 4 seasons | 2020-05-03 - 2020-12-06 / matchday 10
|
38
|
+
#
|
39
|
+
# 2020 => 2020
|
40
|
+
# 2019 => 2019
|
41
|
+
# 2018 => 2018
|
42
|
+
# 2017 => xxx 2017 - requires subscription !!!
|
43
|
+
|
44
|
+
uefa.cl, CL ## note: cl is country code for chile!! - use champs - why? why not?
|
45
|
+
## was europe.cl / cl
|
46
|
+
## todo/check: use champs and NOT cl - why? why not?
|
47
|
+
|
48
|
+
copa.l, CLI
|
49
|
+
## Copa Libertadores
|
50
|
+
|
51
|
+
############
|
52
|
+
## national teams
|
53
|
+
euro, EC
|
54
|
+
world, WC
|
@@ -0,0 +1,27 @@
|
|
1
|
+
key, zone
|
2
|
+
eng, Europe/London
|
3
|
+
es, Europe/Madrid
|
4
|
+
de, Europe/Berlin
|
5
|
+
fr, Europe/Paris
|
6
|
+
it, Europe/Rome
|
7
|
+
|
8
|
+
nl, Europe/Amsterdam
|
9
|
+
pt, Europe/Lisbon
|
10
|
+
|
11
|
+
## for champs default for not to cet (central european time) - why? why not?
|
12
|
+
uefa.cl, Europe/Paris
|
13
|
+
euro, Europe/Paris
|
14
|
+
|
15
|
+
## todo/fix - pt.1
|
16
|
+
## one team in madeira!!! check for different timezone??
|
17
|
+
## CD Nacional da Madeira
|
18
|
+
|
19
|
+
br, America/Sao_Paulo
|
20
|
+
## todo/fix - brazil has 4 timezones
|
21
|
+
## really only two in use for clubs
|
22
|
+
## west and east (amazonas et al)
|
23
|
+
## for now use west for all - why? why not?
|
24
|
+
copa.l, America/Sao_Paulo
|
25
|
+
|
26
|
+
|
27
|
+
## world+2022, add quatar here
|
data/lib/footballdata/convert.rb
CHANGED
@@ -1,41 +1,7 @@
|
|
1
1
|
|
2
|
-
|
3
|
-
|
4
2
|
module Footballdata
|
5
3
|
|
6
4
|
|
7
|
-
TIMEZONES = {
|
8
|
-
'eng.1' => 'Europe/London',
|
9
|
-
'eng.2' => 'Europe/London',
|
10
|
-
|
11
|
-
'es.1' => 'Europe/Madrid',
|
12
|
-
|
13
|
-
'de.1' => 'Europe/Berlin',
|
14
|
-
'fr.1' => 'Europe/Paris',
|
15
|
-
'it.1' => 'Europe/Rome',
|
16
|
-
'nl.1' => 'Europe/Amsterdam',
|
17
|
-
|
18
|
-
'pt.1' => 'Europe/Lisbon',
|
19
|
-
|
20
|
-
## for champs default for not to cet (central european time) - why? why not?
|
21
|
-
'uefa.cl' => 'Europe/Paris',
|
22
|
-
'euro' => 'Europe/Paris',
|
23
|
-
|
24
|
-
## todo/fix - pt.1
|
25
|
-
## one team in madeira!!! check for different timezone??
|
26
|
-
## CD Nacional da Madeira
|
27
|
-
|
28
|
-
'br.1' => 'America/Sao_Paulo',
|
29
|
-
## todo/fix - brazil has 4 timezones
|
30
|
-
## really only two in use for clubs
|
31
|
-
## west and east (amazonas et al)
|
32
|
-
## for now use west for all - why? why not?
|
33
|
-
'copa.l' => 'America/Sao_Paulo',
|
34
|
-
}
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
5
|
def self.convert_score( score )
|
40
6
|
## duration: REGULAR · PENALTY_SHOOTOUT · EXTRA_TIME
|
41
7
|
ft, ht, et, pen = ["","","",""]
|
@@ -123,7 +89,7 @@ def self.convert( league:, season: )
|
|
123
89
|
|
124
90
|
season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
|
125
91
|
|
126
|
-
league_code =
|
92
|
+
league_code = find_league!( league )
|
127
93
|
|
128
94
|
matches_url = Metal.competition_matches_url( league_code, season.start_year )
|
129
95
|
teams_url = Metal.competition_teams_url( league_code, season.start_year )
|
@@ -132,14 +98,10 @@ def self.convert( league:, season: )
|
|
132
98
|
data_teams = Webcache.read_json( teams_url )
|
133
99
|
|
134
100
|
|
135
|
-
## check for time zone
|
136
|
-
tz_name = TIMEZONES[ league.downcase ]
|
137
|
-
if tz_name.nil?
|
138
|
-
puts "!! ERROR - sorry no timezone configured for league #{league}"
|
139
|
-
exit 1
|
140
|
-
end
|
141
101
|
|
142
|
-
|
102
|
+
## check for time zone
|
103
|
+
tz = find_zone!( league: league,
|
104
|
+
season: season )
|
143
105
|
pp tz
|
144
106
|
|
145
107
|
## build a (reverse) team lookup by name
|
@@ -285,10 +247,23 @@ matches.each do |m|
|
|
285
247
|
## utc = ## tz_utc.strptime( m['utcDate'], '%Y-%m-%dT%H:%M:%SZ' )
|
286
248
|
## note: DateTime.strptime is supposed to be unaware of timezones!!!
|
287
249
|
## use to parse utc
|
288
|
-
utc =
|
250
|
+
utc = UTC.strptime( m['utcDate'], '%Y-%m-%dT%H:%M:%SZ' )
|
289
251
|
assert( utc.strftime( '%Y-%m-%dT%H:%M:%SZ' ) == m['utcDate'], 'utc time mismatch' )
|
290
252
|
|
291
|
-
|
253
|
+
|
254
|
+
## assume NOT valid utc time if 00:00
|
255
|
+
## do
|
256
|
+
if utc.hour == 0 && utc.min == 0 &&
|
257
|
+
['SCHEDULED','POSTPONED'].include?( m['status'] )
|
258
|
+
date = utc.strftime( '%Y-%m-%d' )
|
259
|
+
time = ''
|
260
|
+
timezone = ''
|
261
|
+
else
|
262
|
+
local = tz.to_local( utc )
|
263
|
+
date = local.strftime( '%Y-%m-%d' )
|
264
|
+
time = local.strftime( '%H:%M' )
|
265
|
+
timezone = local.strftime( '%Z/%z' )
|
266
|
+
end
|
292
267
|
|
293
268
|
|
294
269
|
## do NOT add time if status is SCHEDULED
|
@@ -301,9 +276,9 @@ matches.each do |m|
|
|
301
276
|
recs << [stage,
|
302
277
|
group,
|
303
278
|
matchday,
|
304
|
-
|
305
|
-
|
306
|
-
|
279
|
+
date,
|
280
|
+
time,
|
281
|
+
timezone,
|
307
282
|
team1,
|
308
283
|
ft,
|
309
284
|
ht,
|
@@ -6,7 +6,7 @@ module Footballdata
|
|
6
6
|
def self.schedule( league:, season: )
|
7
7
|
season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
|
8
8
|
|
9
|
-
league_code =
|
9
|
+
league_code = find_league!( league )
|
10
10
|
puts " mapping league >#{league}< to >#{league_code}<"
|
11
11
|
|
12
12
|
Metal.teams( league_code, season.start_year )
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
def self.matches( league:, season: )
|
18
18
|
season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
|
19
19
|
|
20
|
-
league_code =
|
20
|
+
league_code = find_league!( league )
|
21
21
|
puts " mapping league >#{league}< to >#{league_code}<"
|
22
22
|
Metal.matches( league_code, season.start_year )
|
23
23
|
end
|
@@ -26,7 +26,7 @@ end
|
|
26
26
|
def self.teams( league:, season: )
|
27
27
|
season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
|
28
28
|
|
29
|
-
league_code =
|
29
|
+
league_code = find_league!( league )
|
30
30
|
puts " mapping league >#{league}< to >#{league_code}<"
|
31
31
|
Metal.teams( league_code, season.start_year )
|
32
32
|
end
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
|
39
39
|
class Metal
|
40
40
|
|
41
|
-
def self.get( url,
|
41
|
+
def self.get( url,
|
42
42
|
auth: true,
|
43
43
|
headers: {} )
|
44
44
|
|
@@ -84,19 +84,19 @@ class Metal
|
|
84
84
|
def self.competition_teams_url( code, year ) "#{BASE_URL}/competitions/#{code}/teams?season=#{year}"; end
|
85
85
|
def self.competition_standings_url( code, year ) "#{BASE_URL}/competitions/#{code}/standings?season=#{year}"; end
|
86
86
|
def self.competition_scorers_url( code, year ) "#{BASE_URL}/competitions/#{code}/scorers?season=#{year}"; end
|
87
|
-
|
87
|
+
|
88
88
|
def self.matches( code, year,
|
89
|
-
headers: {} )
|
90
|
-
get( competition_matches_url( code, year ),
|
91
|
-
headers: headers )
|
89
|
+
headers: {} )
|
90
|
+
get( competition_matches_url( code, year ),
|
91
|
+
headers: headers )
|
92
92
|
end
|
93
93
|
|
94
|
-
def self.todays_matches_url( date=Date.today )
|
94
|
+
def self.todays_matches_url( date=Date.today )
|
95
95
|
"#{BASE_URL}/matches?"+
|
96
96
|
"dateFrom=#{date.strftime('%Y-%m-%d')}&"+
|
97
|
-
"dateTo=#{(date+1).strftime('%Y-%m-%d')}"
|
97
|
+
"dateTo=#{(date+1).strftime('%Y-%m-%d')}"
|
98
98
|
end
|
99
|
-
def self.todays_matches( date=Date.today ) ## use/rename to matches_today or such - why? why not?
|
99
|
+
def self.todays_matches( date=Date.today ) ## use/rename to matches_today or such - why? why not?
|
100
100
|
get( todays_matches_url( date ) )
|
101
101
|
end
|
102
102
|
|
data/lib/footballdata/leagues.rb
CHANGED
@@ -1,59 +1,24 @@
|
|
1
1
|
module Footballdata
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
# DED - Eredivisie , Netherlands 10 seasons | 2019-08-09 - 2020-03-08 / matchday 34
|
24
|
-
|
25
|
-
'fr.1' => 'FL1', # incl. team(s) monaco
|
26
|
-
# FL1 - Ligue 1, France
|
27
|
-
# 9 seasons | 2019-08-09 - 2020-05-31 / matchday 38
|
28
|
-
#
|
29
|
-
# 2019 => 2019/20
|
30
|
-
# 2018 => 2018/19
|
31
|
-
# 2017 => xxx 2017-18 - requires subscription !!!
|
32
|
-
|
33
|
-
'it.1' => 'SA',
|
34
|
-
# SA - Serie A , Italy 15 seasons | 2019-08-24 - 2020-08-02 / matchday 27
|
35
|
-
|
36
|
-
'br.1' => 'BSA',
|
37
|
-
# BSA - Série A, Brazil
|
38
|
-
# 4 seasons | 2020-05-03 - 2020-12-06 / matchday 10
|
39
|
-
#
|
40
|
-
# 2020 => 2020
|
41
|
-
# 2019 => 2019
|
42
|
-
# 2018 => 2018
|
43
|
-
# 2017 => xxx 2017 - requires subscription !!!
|
44
|
-
|
45
|
-
## todo/check: use champs and NOT cl - why? why not?
|
46
|
-
'uefa.cl' => 'CL', ## note: cl is country code for chile!! - use champs - why? why not?
|
47
|
-
## was europe.cl / cl
|
48
|
-
|
49
|
-
## Copa Libertadores
|
50
|
-
'copa.l' => 'CLI',
|
51
|
-
|
52
|
-
############
|
53
|
-
## national teams
|
54
|
-
'euro' => 'EC',
|
55
|
-
'world' => 'WC',
|
56
|
-
|
57
|
-
}
|
3
|
+
def self.find_league!( league )
|
4
|
+
@leagues ||= begin
|
5
|
+
recs = read_csv( "#{FootballdataApi.root}/config/leagues.csv" )
|
6
|
+
leagues = {}
|
7
|
+
recs.each do |rec|
|
8
|
+
leagues[ rec['key'] ] = rec['code']
|
9
|
+
end
|
10
|
+
leagues
|
11
|
+
end
|
12
|
+
|
13
|
+
key = league.downcase
|
14
|
+
code = @leagues[ key ]
|
15
|
+
if code.nil?
|
16
|
+
puts "!! ERROR - no code/mapping found for league >#{league}<"
|
17
|
+
puts " mappings include:"
|
18
|
+
pp @leagues
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
code
|
22
|
+
end
|
58
23
|
end # module Footballdata
|
59
24
|
|
data/lib/footballdata/teams.rb
CHANGED
@@ -8,9 +8,9 @@ module Footballdata
|
|
8
8
|
def self.export_teams( league:, season: )
|
9
9
|
|
10
10
|
season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
|
11
|
-
league_code =
|
11
|
+
league_code = find_league!( league )
|
12
12
|
|
13
|
-
teams_url = Metal.competition_teams_url( league_code,
|
13
|
+
teams_url = Metal.competition_teams_url( league_code,
|
14
14
|
season.start_year )
|
15
15
|
data_teams = Webcache.read_json( teams_url )
|
16
16
|
|
@@ -22,12 +22,12 @@ def self.export_teams( league:, season: )
|
|
22
22
|
clubs = {} ## by country
|
23
23
|
|
24
24
|
data_teams['teams'].each do |rec|
|
25
|
-
|
26
|
-
buf = String.new ### use for string buffer (or String.new('') - why? why not?
|
25
|
+
|
26
|
+
buf = String.new ### use for string buffer (or String.new('') - why? why not?
|
27
27
|
buf << "#{rec['name']}"
|
28
28
|
buf << ", #{rec['founded']}" if rec['founded']
|
29
|
-
if rec['venue']
|
30
|
-
buf << ", @ #{rec['venue']}"
|
29
|
+
if rec['venue']
|
30
|
+
buf << ", @ #{rec['venue']}"
|
31
31
|
# buf << " # #{rec['area']['name']}"
|
32
32
|
end
|
33
33
|
buf << "\n"
|
@@ -39,7 +39,7 @@ def self.export_teams( league:, season: )
|
|
39
39
|
|
40
40
|
alt_names << " | #{rec['tla']}" if rec['tla'] &&
|
41
41
|
rec['tla'] != rec['name']
|
42
|
-
|
42
|
+
|
43
43
|
if alt_names.size > 0
|
44
44
|
buf << " "
|
45
45
|
buf << alt_names
|
@@ -48,7 +48,7 @@ def self.export_teams( league:, season: )
|
|
48
48
|
|
49
49
|
## clean null in address (or keep nulls) - why? why not?
|
50
50
|
## e.g. null Rionegro null
|
51
|
-
## Calle 104 No. 13a - 32 Bogotá null
|
51
|
+
## Calle 104 No. 13a - 32 Bogotá null
|
52
52
|
|
53
53
|
buf << " address: #{rec['address'].gsub( /\bnull\b/, '')}"
|
54
54
|
buf << "\n"
|
@@ -57,21 +57,21 @@ def self.export_teams( league:, season: )
|
|
57
57
|
buf << " colors: #{rec['clubColors']}"
|
58
58
|
buf << "\n"
|
59
59
|
|
60
|
-
country = rec['area']['name']
|
60
|
+
country = rec['area']['name']
|
61
61
|
ary = clubs[ country] ||= []
|
62
62
|
ary << buf
|
63
63
|
end
|
64
64
|
# puts buf
|
65
|
-
|
65
|
+
|
66
66
|
## pp clubs
|
67
67
|
|
68
|
-
|
68
|
+
|
69
69
|
buf = String.new
|
70
70
|
|
71
71
|
if clubs.size > 1
|
72
72
|
clubs.each do |country, ary|
|
73
73
|
buf << "# #{country} - #{ary.size} clubs\n"
|
74
|
-
end
|
74
|
+
end
|
75
75
|
buf << "\n"
|
76
76
|
end
|
77
77
|
|
@@ -82,9 +82,8 @@ def self.export_teams( league:, season: )
|
|
82
82
|
end
|
83
83
|
|
84
84
|
path = "#{config.convert.out_dir}/#{season.to_path}/#{league.downcase}.clubs.txt"
|
85
|
-
write_text( path, buf )
|
85
|
+
write_text( path, buf )
|
86
86
|
end
|
87
87
|
|
88
88
|
|
89
89
|
end # module Footballdata
|
90
|
-
|
@@ -0,0 +1,97 @@
|
|
1
|
+
|
2
|
+
class UTC
|
3
|
+
def self.now() Time.now.utc; end
|
4
|
+
def self.today() now.to_date; end
|
5
|
+
|
6
|
+
## -- todo - make sure / assert it's always utc - how???
|
7
|
+
## utc = ## tz_utc.strptime( m['utcDate'], '%Y-%m-%dT%H:%M:%SZ' )
|
8
|
+
## note: DateTime.strptime is supposed to be unaware of timezones!!!
|
9
|
+
## use to parse utc
|
10
|
+
## quick hack -
|
11
|
+
## use to_time.getutc instead of utc ???
|
12
|
+
def self.strptime( str, format )
|
13
|
+
DateTime.strptime( str, format ).to_time.utc
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.find_zone( name )
|
17
|
+
zone = TZInfo::Timezone.get( name )
|
18
|
+
## wrap tzinfo timezone in our own - for adding more (auto)checks etc.
|
19
|
+
zone ? Timezone.new( zone ) : nil
|
20
|
+
end
|
21
|
+
|
22
|
+
class Timezone ## nested inside UTC
|
23
|
+
## todo/fix
|
24
|
+
## cache timezone - why? why not?
|
25
|
+
def initialize( zone )
|
26
|
+
@zone = zone
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_local( time )
|
30
|
+
## assert time is Time (not Date or DateTIme)
|
31
|
+
## and assert utc!!!
|
32
|
+
assert( time.is_a?( Time ), "time #{time} is NOT of class Time; got #{time.class.name}" )
|
33
|
+
assert( time.utc?, "time #{time} is NOT utc; utc? returns #{time.utc?}" )
|
34
|
+
local = @zone.to_local( time )
|
35
|
+
local
|
36
|
+
end
|
37
|
+
|
38
|
+
def assert( cond, msg )
|
39
|
+
if cond
|
40
|
+
# do nothing
|
41
|
+
else
|
42
|
+
puts "!!! assert failed - #{msg}"
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end # class Timezone
|
47
|
+
end # class UTC
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
module Footballdata
|
52
|
+
def self.find_zone!( league:, season: )
|
53
|
+
@zones ||= begin
|
54
|
+
recs = read_csv( "#{FootballdataApi.root}/config/timezones.csv" )
|
55
|
+
zones = {}
|
56
|
+
recs.each do |rec|
|
57
|
+
zone = UTC.find_zone( rec['zone'] )
|
58
|
+
if zone.nil?
|
59
|
+
## raise ArgumentError - invalid zone
|
60
|
+
puts "!! ERROR - cannot find timezone in timezone db:"
|
61
|
+
pp rec
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
zones[ rec['key']] = zone
|
65
|
+
end
|
66
|
+
zones
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
## lookup first try by league+season
|
71
|
+
league_code = league.downcase
|
72
|
+
season = Season( season )
|
73
|
+
|
74
|
+
## e.g. world+2022, etc.
|
75
|
+
key = "#{league_code}+#{season}"
|
76
|
+
zone = @zones[key]
|
77
|
+
|
78
|
+
## try league e.g. eng.1 etc.
|
79
|
+
zone = @zones[league_code] if zone.nil?
|
80
|
+
|
81
|
+
## try first code only (country code )
|
82
|
+
if zone.nil?
|
83
|
+
code, _ = league_code.split( '.', 2 )
|
84
|
+
zone = @zones[code]
|
85
|
+
end
|
86
|
+
|
87
|
+
if zone.nil? ## still not found; report error
|
88
|
+
puts "!! ERROR: no timezone found for #{league} #{season}"
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
zone
|
93
|
+
end
|
94
|
+
end # module Footballdata
|
95
|
+
|
96
|
+
|
97
|
+
|
data/lib/footballdata/version.rb
CHANGED
data/lib/footballdata.rb
CHANGED
@@ -36,6 +36,8 @@ end # module Footballdata
|
|
36
36
|
# our own code
|
37
37
|
require_relative 'footballdata/version'
|
38
38
|
require_relative 'footballdata/leagues'
|
39
|
+
require_relative 'footballdata/timezones'
|
40
|
+
|
39
41
|
require_relative 'footballdata/download'
|
40
42
|
require_relative 'footballdata/prettyprint'
|
41
43
|
|
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.3.
|
4
|
+
version: 0.3.1
|
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-
|
11
|
+
date: 2024-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tzinfo
|
@@ -116,6 +116,8 @@ files:
|
|
116
116
|
- README.md
|
117
117
|
- Rakefile
|
118
118
|
- bin/fbdat
|
119
|
+
- config/leagues.csv
|
120
|
+
- config/timezones.csv
|
119
121
|
- lib/footballdata.rb
|
120
122
|
- lib/footballdata/convert.rb
|
121
123
|
- lib/footballdata/download.rb
|
@@ -124,6 +126,7 @@ files:
|
|
124
126
|
- lib/footballdata/prettyprint.rb
|
125
127
|
- lib/footballdata/stat.rb
|
126
128
|
- lib/footballdata/teams.rb
|
129
|
+
- lib/footballdata/timezones.rb
|
127
130
|
- lib/footballdata/version.rb
|
128
131
|
homepage: https://github.com/sportdb/sport.db
|
129
132
|
licenses:
|