footballdata-api 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16f099d030a007993b7289956e920fd89baff6abc506feeca3dad792453efe76
4
- data.tar.gz: 8f3d2df27a3dc12cc15fa2a8ee0dcd42a51ed793261a2ab2795020147596e7f6
3
+ metadata.gz: b3350fb47d596e6d5b2e4d73582b2615020d56db38cf86d9545a10b1760494c1
4
+ data.tar.gz: d7ba6c51f3e12beed59df7b851e8d533a838de67e73c5b1d025ab7a1256caa7d
5
5
  SHA512:
6
- metadata.gz: cca1d63da2e1823a3c9cc2636953da2f691101c32b63f5004c5349338d9dd75099ac993786e038cf3e2ea8a41f3ac1ce7510cdf148f1f13a98d360203613cf99
7
- data.tar.gz: 6030f680eb2e5dadd269ee78bd778c1b465914702e20fe98e55e0967346feb67a6b74d8a965dea73ce62b9c8f457ba1de811d02e26a603b90ff4d3a160b8ee99
6
+ metadata.gz: 2943bcf6f2da49dfc1cab26da0933957d2bde2fb13749c7ce4d4896214484bac3edcea197e01ed9b2b63f92e2e74f560ac49189f63be7644522b7b24b7cbed73
7
+ data.tar.gz: 945cc2d0cb9346434c6f3875c33dd153867318b73e067c5574bc6e789f7b3b293d5c7f126c80221c676998eaa0e532647b7a25b960d082097209b6a1428f879e
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.2.0
1
+ ### 0.3.1
2
2
 
3
3
  ### 0.0.1 / 2024-07-03
4
4
 
data/Manifest.txt CHANGED
@@ -3,13 +3,15 @@ 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
9
- lib/footballdata/generator.rb
10
11
  lib/footballdata/leagues.rb
11
12
  lib/footballdata/mods.rb
12
13
  lib/footballdata/prettyprint.rb
13
14
  lib/footballdata/stat.rb
14
15
  lib/footballdata/teams.rb
16
+ lib/footballdata/timezones.rb
15
17
  lib/footballdata/version.rb
data/Rakefile CHANGED
@@ -19,15 +19,15 @@ Hoe.spec 'footballdata-api' do
19
19
 
20
20
  self.extra_deps = [
21
21
  ['tzinfo'],
22
- ['season-formats'],
23
- ['webget'],
22
+ ['season-formats'],
23
+ ['webget'],
24
24
  ['cocos'], ## later pull in with sportsdb-writers
25
25
  ]
26
26
 
27
27
  self.licenses = ['Public Domain']
28
28
 
29
29
  self.spec_extras = {
30
- required_ruby_version: '>= 2.2.2'
30
+ required_ruby_version: '>= 3.1.0'
31
31
  }
32
32
 
33
33
  end
data/bin/fbdat CHANGED
@@ -12,17 +12,20 @@ load_env ## use dotenv (.env)
12
12
  Webcache.root = if File.exist?( '/sports/cache' )
13
13
  puts " setting web cache to >/sports/cache<"
14
14
  '/sports/cache'
15
- else
15
+ else
16
16
  './cache'
17
17
  end
18
18
 
19
- ## note - free tier (tier one) plan - 10 requests/minute
19
+ ## note - free tier (tier one) plan - 10 requests/minute
20
20
  ## (one request every 6 seconds 6*10=60 secs)
21
21
  ## 10 API calls per minute max.
22
22
  ## note - default sleep (delay in secs) is 3 sec(s)
23
23
  Webget.config.sleep = 10
24
24
 
25
25
 
26
+ Footballdata.config.convert.out_dir = '/sports/cache.api.fbdat' if File.exist?( '/sports/cache.api.fbdat' )
27
+
28
+
26
29
 
27
30
 
28
31
  require 'optparse'
@@ -32,17 +35,28 @@ require 'optparse'
32
35
  module Footballdata
33
36
  def self.main( args=ARGV )
34
37
 
35
- opts = {}
38
+ opts = {
39
+ cached: false,
40
+ convert: true,
41
+ }
42
+
36
43
  parser = OptionParser.new do |parser|
37
- parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
44
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] [args]"
38
45
 
39
46
  parser.on( "--cache", "--cached", "--offline",
40
- "use cached data in #{Webcache.root}" ) do |cached|
47
+ "use cached data in #{Webcache.root} - default is (#{opts[:cached]})" ) do |cached|
41
48
  opts[:cached] = cached
42
49
  end
50
+
51
+ parser.on( "--no-convert",
52
+ "turn off conversion to .csv in #{Footballdata.config.convert.out_dir} - default is (#{!opts[:convert]})" ) do |convert|
53
+ opts[:convert] = !convert
54
+ end
43
55
  end
44
56
  parser.parse!( args )
45
57
 
58
+
59
+
46
60
  puts "OPTS:"
47
61
  p opts
48
62
  puts "ARGV:"
@@ -51,23 +65,23 @@ p args
51
65
 
52
66
  ## try special args
53
67
 
54
- if ['plan', 'plans',
55
- 'comp', 'comps'].include?(args[0])
68
+ if ['plan', 'plans',
69
+ 'comp', 'comps'].include?(args[0])
56
70
 
57
71
  if opts[:cached]
58
72
  ## do nothing
59
- else
73
+ else
60
74
  Metal.competitions( auth: true ) ## get free tier (TIER_ONE) with auth (token)
61
75
  end
62
76
 
63
77
  url = Metal.competitions_url
64
78
  pp url
65
79
  #=> "http://api.football-data.org/v4/competitions"
66
-
80
+
67
81
  data = Webcache.read_json( url )
68
82
  pp data
69
-
70
- comps = data['competitions']
83
+
84
+ comps = data['competitions']
71
85
  comps.each do |rec|
72
86
  print "==> "
73
87
  print "#{rec['area']['name']} (#{rec['area']['code']}) - "
@@ -75,12 +89,12 @@ if ['plan', 'plans',
75
89
  print "#{rec['plan']} #{rec['type']}, "
76
90
  print "#{rec['numberOfAvailableSeasons']} season(s)"
77
91
  print "\n"
78
-
79
- print " #{rec['currentSeason']['startDate']} - #{rec['currentSeason']['endDate']} "
92
+
93
+ print " #{rec['currentSeason']['startDate']} - #{rec['currentSeason']['endDate']} "
80
94
  print "@ #{rec['currentSeason']['currentMatchday']}"
81
95
  print "\n"
82
96
  end
83
-
97
+
84
98
  puts " #{comps.size} competition(s)"
85
99
  exit 0
86
100
  end
@@ -100,9 +114,9 @@ end
100
114
  ## todo - add more date offsets - t+2,t+3,t+4, etc.
101
115
 
102
116
  date = if ['y', 'yesterday', 't-1', '-1'].include?( args[0] )
103
- Date.today-1
117
+ Date.today-1
104
118
  elsif ['t', 'tomorrow', 't+1', '1', '+1'].include?( args[0] )
105
- Date.today+1
119
+ Date.today+1
106
120
  elsif ['m', 'match', 'matches', 'today'].include?( args[0] || 'today' ) ## make default - why? why not?
107
121
  Date.today
108
122
  else
@@ -110,7 +124,7 @@ date = if ['y', 'yesterday', 't-1', '-1'].include?( args[0] )
110
124
  end
111
125
 
112
126
  if date
113
- if opts[:cached]
127
+ if opts[:cached]
114
128
  ## do nothing
115
129
  else
116
130
  Metal.todays_matches( date )
@@ -124,7 +138,7 @@ if date
124
138
  ## only print competition header if different from last match
125
139
  comp = fmt_competition( rec )
126
140
  puts comp if comp != last_comp
127
-
141
+
128
142
  puts fmt_match( rec )
129
143
 
130
144
  last_comp = comp
@@ -145,40 +159,41 @@ end
145
159
  ## club cups intl
146
160
  ## CL 2023 - (uefa/european) champions league
147
161
  ## CLI 2204 - (south american) copa libertadores
148
- ## club leagues
162
+ ## club leagues
149
163
  ## PL 2024 - england premiere league
150
164
 
165
+ ##
166
+ ## note - only use "generic" uniform league codes for now!!
151
167
 
152
- league_code = args[0] || 'PL'
168
+ league_code = (args[0] || 'eng.1').downcase
153
169
 
170
+ ## todo - find a better name
171
+ ## use internal_league_code or such - why? why not?
154
172
  ### convenience helpers - lets you use eng.1, euro, etc.
155
173
  ## check if mapping for league_code
156
- if LEAGUES.has_key?( league_code.downcase )
157
- league_code = LEAGUES[ league_code.downcase ]
158
- else
159
- ## assume "native" code
160
- ## always upcase e.g. pl => PL etc.
161
- league_code = league_code.upcase
162
- end
174
+ metal_league_code = find_league!( league_code )
163
175
 
164
176
 
165
- season = Season( args[1] ||
166
- (league_code == 'EC' ? '2024' : '2024/25'))
177
+ season = Season( args[1] ||
178
+ (['euro',
179
+ 'copa.l',
180
+ 'br.1'].include?(league_code) ? '2024' : '2024/25'))
167
181
 
168
182
  season_start_year = season.start_year ## use year - why? why not?
169
183
 
170
- pp league_code, season_start_year
184
+ pp [metal_league_code, season_start_year]
171
185
 
172
186
  if opts[:cached]
173
187
  ## do nothing
174
188
  else
175
189
  ## download dataset(s)
176
190
  ## try download
177
- Metal.matches( league_code,
178
- season_start_year )
179
- end
191
+ ## note: include teams (for convert) for now too!!
192
+ Metal.teams( metal_league_code, season_start_year )
193
+ Metal.matches( metal_league_code, season_start_year )
194
+ end
180
195
 
181
- url = Metal.competition_matches_url( league_code,
196
+ url = Metal.competition_matches_url( metal_league_code,
182
197
  season_start_year )
183
198
  pp url
184
199
  #=> "http://api.football-data.org/v4/competitions/EC/matches?season=2024"
@@ -188,6 +203,13 @@ data = Webcache.read_json( url )
188
203
 
189
204
  pp_matches( data )
190
205
 
206
+
207
+ if opts[:convert]
208
+ puts "==> converting to .csv"
209
+ convert( league: league_code, season: season )
210
+ end
211
+
212
+
191
213
  end # def self.main
192
214
  end # module Footballdata
193
215
 
@@ -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