fbup 0.1.3 → 0.2.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: d115aef45d2af98f2e9888dec2ac6efc7dac781eb4caf5066b31ab6dbfd0f391
4
- data.tar.gz: 1c435a5430e5966b96783c0c0dc24825fc299cb293b4fb207c1c38185865d1db
3
+ metadata.gz: c0cc7c6bdb92fe41bd89ddf67258bf59ce8feb70ad16c9b1908fdda37f165c03
4
+ data.tar.gz: 3d7cc168bd623108f549e4c531738350065a1c7743ffd42ab0a7d7e66d89c8d1
5
5
  SHA512:
6
- metadata.gz: 0e4ab909468866bab66ccbc20cdabe583068712b97a24358b57d91188c6e962dfadae7ec75cf405b261786fbc2349a0ea944f00f1270638f7c280e5b601bb844
7
- data.tar.gz: edc46e659a27cfdfb00ef71c22ea2957690c2a441549984a1e2f8df81792279ac3d448071057718b2c2abac0fc62f3d2da43b448e5ce37c09e6e48357e59adff
6
+ metadata.gz: 4851fcc456089aa461f5fa01f2866c414acfa5ed75e921e58e28224fa2a23e8190e581627d36637732d4065a7a01d06f1d7c0843b26f9e7d5e3154dc1041f1c4
7
+ data.tar.gz: 5c38c8ea0aa370ad42e1f9a7be5b2df211bd0989af16d14efe7a634ec5ffe07c10884a4ff672035ae396a8ce8dd0ded746ee136c8bacf63806ccda4dc27ca856
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.1.3
1
+ ### 0.2.1
2
2
  ### 0.0.1 / 2024-12-29
3
3
 
4
4
  * Everything is new. First release.
data/Manifest.txt CHANGED
@@ -3,9 +3,11 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  bin/fbup
6
+ config/leagues.csv
6
7
  config/openfootball.csv
7
8
  lib/fbup.rb
8
9
  lib/fbup/github.rb
9
10
  lib/fbup/github_config.rb
11
+ lib/fbup/league_config.rb
10
12
  lib/fbup/main.rb
11
13
  lib/fbup/version.rb
data/Rakefile CHANGED
@@ -21,8 +21,8 @@ Hoe.spec 'fbup' do
21
21
 
22
22
  self.extra_deps = [
23
23
  ['gitti', '>= 0.6.1'],
24
- ['sportdb-writers', '>= 0.4.1'],
25
- ['football-timezones', '>= 0.3.0'],
24
+ ['sportdb-writers', '>= 0.4.3'],
25
+ ['leagues', '>= 0.2.1'],
26
26
  ]
27
27
 
28
28
  self.spec_extras = {
data/bin/fbup CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
  ## note - quick hack - auto-add local football timezones
10
- $LOAD_PATH.unshift( '/sports/sportdb/sport.db/timezones/lib' )
10
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/leagues/lib' )
11
11
  $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
12
12
  require 'fbup'
13
13
 
@@ -0,0 +1,111 @@
1
+ code,basename,start_season,end_season
2
+
3
+ ########
4
+ ### use a "custom" basename for "classic" leagues
5
+
6
+
7
+ ####
8
+ ## /austria
9
+ at.1,1-bundesliga,,
10
+ ## -- add new name - Erste Liga => 2. Liga
11
+ at.2,2-liga2,2018/19,
12
+ at.2,2-liga1,,2017/18
13
+ at.3.o,3-regionalliga-ost,,
14
+ at.3.m,3-regionalliga-mitte,,
15
+ at.3.w,3-regionalliga-west,,
16
+ at.3.sbg,3-regionalliga-salzburg,,
17
+ at.3.t,3-regionalliga-tirol,,
18
+ at.3.v,3-regionalliga-vorarlberg,,
19
+ at.cup,cup,,
20
+
21
+ ####
22
+ ## /deutschland
23
+ de.1,1-bundesliga,,
24
+ de.2,2-bundesliga2,,
25
+ de.3,3-liga3,,
26
+ de.cup,cup,,
27
+ de.super,super,,
28
+ de.4.nord,4-regionalliga-nord,,
29
+ de.4.nordost,4-regionalliga-nordost,,
30
+ de.4.west,4-regionalliga-west,,
31
+ de.4.suedwest,4-regionalliga-suedwest,,
32
+ de.4.bayern,4-regionalliga-bayern,,
33
+ # -- add alternate keys for de.4
34
+ # todo/fix - find a way to add alternate keys (WITHOUT repeating basename) !!!
35
+ de.4.n,4-regionalliga-nord,,
36
+ de.4.no,4-regionalliga-nordost,,
37
+ de.4.w,4-regionalliga-west,,
38
+ de.4.sw,4-regionalliga-suedwest,,
39
+
40
+ ################
41
+ ## /england
42
+ eng.2,2-championship,2004/05,
43
+ eng.3,3-league1,2004/05,
44
+ eng.4,4-league2,2004/05,
45
+
46
+ eng.1,1-premierleague,1992/93,
47
+ eng.2,2-division1,1992/93,2003/04
48
+ eng.3,3-division2,1992/93,2003/04
49
+ eng.4,4-division3,1992/93,2003/04
50
+ eng.5,5-nationalleague,1992/93,
51
+
52
+ eng.1,1-division1,1892/93,1991/92
53
+ eng.2,2-division2,1892/93,1991/92
54
+ eng.3,3-division3,,1991/92
55
+ eng.3.a,3-division3-north,,
56
+ eng.3.b,3-division3-south,,
57
+ eng.1,1-footballleague,1888/89,1891/92
58
+
59
+
60
+ ###
61
+ ## fix - always use fa.cup and efl.cup - why? why not?
62
+ eng.cup,facup,, ## FA CuP
63
+ eng.super,super,, ## FA Community Shield
64
+ eng.cup.l,eflcup,, ## EFL Cup
65
+ eng.cup.t,efltrophy,, ## EFL Trophy
66
+ eng.cup.t.ii,fatrophy,, ## FA Trophy
67
+
68
+ ## -- add alternate codes / keys
69
+ eng.fa.cup,facup,, ## FA Cup
70
+ eng.efl.cup,eflcup,, ## EFL Cup
71
+
72
+
73
+ #######
74
+ ## /espana
75
+ es.1,1-liga,,
76
+ es.2,2-liga2,,
77
+ es.3,3-liga2b,, ## Segunda División B
78
+ es.cup,cup,,
79
+ es.super,supercopa,, ## check - use only super - why? why not?
80
+
81
+
82
+ #####
83
+ ## /italy
84
+ it.1,1-seriea,,
85
+ it.2,2-serieb,,
86
+ it.3.a,3-seriec_a,, ## North & Central West
87
+ it.3.b,3-seriec_b,, ## North & Central East
88
+ it.3.c,3-seriec_c,, ## South
89
+ it.cup,cup,,
90
+ it.super,super,,
91
+ ## it.cup.c -- Italian Coppa Italia Serie C
92
+
93
+
94
+ #####
95
+ ## /champions-league - uefa incl. europa & conference
96
+ uefa.cl, cl,,
97
+ uefa.champs, cl,,
98
+ uefa.el, el,,
99
+ uefa.europa, el,,
100
+ uefa.conf, conf,,
101
+ uefa.con, conf,,
102
+
103
+ #####
104
+ ## /club-worldcup
105
+ world.clubs, clubworldcup,,
106
+ world.club, clubworldcup,,
107
+ ## - use world.clubs or club ??
108
+
109
+
110
+
111
+
@@ -131,12 +131,13 @@ jp, world/asia/japan,
131
131
  kz, world/asia/kazakhstan,
132
132
 
133
133
  il, world/middle-east/israel,
134
+ sa, world/middle-east/saudi-arabia,
134
135
 
135
136
 
136
137
  mls, world/north-america/major-league-soccer,
137
138
 
138
139
 
139
- mx, world/north-america/mexico,
140
+ mx, world/north-america/mexico,
140
141
 
141
142
 
142
143
  ## fix/change concacaf.cl to concacaf.champs !!!
@@ -148,4 +149,11 @@ concacaf.champs, world/north-america/champions-league,
148
149
  au, world/pacific/australia,
149
150
 
150
151
 
151
- world, worldcup, ## add custom flag - why? why not?
152
+ ## use world.clubs or club ??
153
+ world.clubs, club-worldcup, classic ## use classic setup for now - why? why not?
154
+ world.club, club-worldcup, classic
155
+
156
+
157
+
158
+ world, worldcup, ## add custom flag - why? why not?
159
+
data/lib/fbup/github.rb CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- module Fbup
2
+ module Fbup ### rename module to Up - why? why not?
3
3
 
4
4
  ###
5
5
  ## todo/fix:
@@ -0,0 +1,99 @@
1
+ module Fbup
2
+
3
+ ####
4
+ ### check - rename to ExtraLeagueConfig or such - why? why not?
5
+
6
+ class LeagueConfig
7
+
8
+ def self.find_by( code:, season: )
9
+ ## return league code record/item or nil
10
+ builtin.find_by( code: code, season: season )
11
+ end
12
+
13
+
14
+ #####
15
+ ## (static) helpers
16
+ def self.builtin
17
+ ## get builtin league code index (build on demand)
18
+ @leagues ||= begin
19
+ leagues = LeagueConfig.new
20
+ ['leagues',
21
+ ].each do |name|
22
+ recs = read_csv( "#{SportDb::Module::Fbup.root}/config/#{name}.csv" )
23
+ leagues.add( recs )
24
+ end
25
+ leagues
26
+ end
27
+ @leagues
28
+ end
29
+
30
+
31
+ def self.norm( code ) ## use norm_(league)code - why? why not?
32
+ ## norm league code
33
+ ## downcase
34
+ ## and remove all non-letters/digits e.g. at.1 => at1, at 1 => at1 etc.
35
+ ## ö.1 => ö1
36
+ ## note - allow unicode letters!!!
37
+ ## note - assume downcase works for unicode too e.g. Ö=>ö
38
+ ## for now no need to use our own downcase - why? why not?
39
+
40
+ code.downcase.gsub( /[^\p{Ll}0-9]/, '' )
41
+ end
42
+
43
+
44
+
45
+
46
+ def initialize
47
+ @leagues = {}
48
+ end
49
+
50
+
51
+ def add( recs )
52
+ recs.each do |rec|
53
+ key = LeagueConfig.norm( rec['code'] )
54
+ @leagues[ key ] ||= []
55
+
56
+ ## note: auto-change seasons to season object or nil
57
+ @leagues[ key ] << { 'code' => rec['code'],
58
+ 'basename' => rec['basename'],
59
+ 'start_season' => rec['start_season'].empty? ? nil : Season.parse( rec['start_season'] ),
60
+ 'end_season' => rec['end_season'].empty? ? nil : Season.parse( rec['end_season'] ),
61
+ }
62
+ end
63
+ end
64
+
65
+
66
+ def find_by( code:, season: )
67
+ raise ArgumentError, "league code as string|symbol expected" unless code.is_a?(String) || code.is_a?(Symbol)
68
+
69
+ ## return league code record/item or nil
70
+ ## check for alt code first
71
+ season = Season( season )
72
+ key = LeagueCodes.norm( code )
73
+ rec = nil
74
+
75
+ recs = @leagues[ key ]
76
+
77
+ if recs
78
+ rec = _find_by_season( recs, season )
79
+ end
80
+
81
+ rec ## return nil if no code record/item found
82
+ end
83
+
84
+
85
+ def _find_by_season( recs, season )
86
+ recs.each do |rec|
87
+ start_season = rec['start_season']
88
+ end_season = rec['end_season']
89
+ return rec if (start_season.nil? || start_season <= season) &&
90
+ (end_season.nil? || end_season >= season)
91
+ end
92
+ nil
93
+ end
94
+
95
+
96
+ end # class LeagueConfig
97
+
98
+
99
+ end # module Fbup
data/lib/fbup/main.rb CHANGED
@@ -115,17 +115,27 @@ puts "ARGV:"
115
115
  p args
116
116
 
117
117
 
118
+
119
+ source_path = opts[:source_path]
120
+
121
+ ### get latest season with autofiller
122
+ ## todo use new LeaguesetAutofiller class - why? why not?
123
+ ## or move code of autofiller here - why? why not?
124
+ ##
125
+ autofiller = ->(league_query) {
126
+ Leagueset.autofiller( league_query, source_path: source_path )
127
+ }
128
+
118
129
  datasets = if opts[:file]
119
- read_leagueset( opts[:file] )
130
+ read_leagueset( opts[:file], autofill: autofiller )
120
131
  else
121
- parse_leagueset_args( args )
132
+ parse_leagueset_args( args, autofill: autofiller )
122
133
  end
123
134
 
124
135
  puts "datasets:"
125
136
  pp datasets
126
137
 
127
138
 
128
- source_path = opts[:source_path]
129
139
 
130
140
  root_dir = if opts[:test]
131
141
  opts[:test_dir]
@@ -147,18 +157,37 @@ pp sync
147
157
 
148
158
  sync.git_fast_forward_if_clean if opts[:ffwd]
149
159
 
160
+
150
161
  ### step 0 - validate and fill-in seasons etc.
162
+ ##
163
+ ## todo/fix - remove fill-in seasons from validate!!
164
+ ## use new autofill on init!!!
151
165
  datasets.validate!( source_path: source_path )
152
166
 
153
167
 
154
- datasets.each do |league_key, seasons|
155
- puts "==> gen #{league_key} - #{seasons.size} seasons(s)..."
168
+ ##
169
+ ## note - use league_query (or league_qkey or _querykey) or such
170
+ ## for user supplied key to compute/find the canoncial league code
171
+
172
+ datasets.each do |league_query, seasons|
173
+ puts "==> gen #{league_query} - #{seasons.size} seasons(s)..."
156
174
 
157
- league_info = find_league_info( league_key )
158
- pp league_info
159
175
 
160
176
  seasons.each do |season|
161
- filename = "#{season.to_path}/#{league_key}.csv"
177
+ ## note - league info requires season
178
+ ## PLUS use (canoncial) league code from info!!!
179
+ league_info = LeagueCodes.find_by( code: league_query, season: season )
180
+ pp league_info
181
+
182
+ league_code = league_info[ 'code' ]
183
+ league_name = league_info[ 'name' ] # e.g. Brasileiro Série A
184
+
185
+ ### todo/fix - move basename out of league_info
186
+ ### make it github/openfootball "legacy" code
187
+ ## basename = league_info[ 'basename' ] #.e.g 1-seriea
188
+
189
+
190
+ filename = "#{season.to_path}/#{league_code}.csv"
162
191
  path = find_file( filename, path: source_path )
163
192
 
164
193
  ### get matches
@@ -168,7 +197,7 @@ datasets.each do |league_key, seasons|
168
197
 
169
198
 
170
199
  ## get repo config for flags and more
171
- repo = GitHubSync::REPOS[ league_key ]
200
+ repo = GitHubSync::REPOS[ league_code ]
172
201
  flags = repo['flags'] || {}
173
202
  classic_flag = flags['classic'] || false
174
203
 
@@ -184,18 +213,22 @@ datasets.each do |league_key, seasons|
184
213
  puts txt if opts[:debug]
185
214
 
186
215
 
187
- league_name = league_info[ :name ] # e.g. Brasileiro Série A
188
- basename = league_info[ :basename] #.e.g 1-seriea
189
-
190
- league_name = league_name.call( season ) if league_name.is_a?( Proc ) ## is proc/func - name depends on season
191
- basename = basename.call( season ) if basename.is_a?( Proc ) ## is proc/func - name depends on season
192
-
193
-
216
+
217
+ basename = nil
194
218
  if classic_flag || opts[:classic]
195
- ## do nothing
219
+ league_config = LeagueConfig.find_by( code: league_query, season: season )
220
+ if league_config.nil?
221
+ puts "!! ERROR - basename league config required for classic format; no config found for #{league_query} #{season}; sorry"
222
+ exit 1
223
+ end
224
+ basename = league_config['basename']
196
225
  else
197
- ## add quick fix for new league name overwrites
198
- league_name = LEAGUE_NAMES_V2[league_key] || league_name
226
+ ## change base name to league key
227
+ ## todo - fix - make gsub smarter
228
+ ## change at.cup to at_cup - why? why not?
229
+ basename = league_code.gsub( '.', '' )
230
+ ## bonus - add quick fix for new league name overwrites
231
+ league_name = LEAGUE_NAMES_V2[league_code] || league_name
199
232
  end
200
233
 
201
234
 
@@ -214,11 +247,7 @@ datasets.each do |league_key, seasons|
214
247
  outpath += if classic_flag || opts[:classic]
215
248
  "/#{season.to_path}/#{basename}.txt"
216
249
  else
217
- ## add season "inline" (to basename) or use dir
218
- ## change base name to league key
219
- ## todo - fix - make gsub smarter
220
- ## change at.cup to at_cup - why? why not?
221
- basename = league_key.gsub( '.', '' )
250
+ ## note - add season "inline" (to basename) or use dir
222
251
  "/#{season.to_path}_#{basename}.txt"
223
252
  end
224
253
 
data/lib/fbup/version.rb CHANGED
@@ -3,8 +3,8 @@ module SportDb
3
3
  module Module
4
4
  module Fbup
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 1
7
- PATCH = 3
6
+ MINOR = 2
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
data/lib/fbup.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  require 'sportdb/writers'
3
- require 'football/timezones' ## pulls-in find_league_info, etc.
3
+ require 'leagues' ## pulls-in find_league_info, etc.
4
4
 
5
5
 
6
6
  require 'optparse' ## command-line processing; check if included updstream?
@@ -18,6 +18,7 @@ require_relative 'fbup/version'
18
18
  require_relative 'fbup/github_config'
19
19
  require_relative 'fbup/github' ## github helpers/update machinery
20
20
 
21
+ require_relative 'fbup/league_config' ## for "classic" custom basenames e.g. eng.1 => 1-premierleague etc.
21
22
 
22
23
  require_relative 'fbup/main'
23
24
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.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: 2025-03-26 00:00:00.000000000 Z
11
+ date: 2025-05-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gitti
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.4.1
33
+ version: 0.4.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.4.1
40
+ version: 0.4.3
41
41
  - !ruby/object:Gem::Dependency
42
- name: football-timezones
42
+ name: leagues
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 0.3.0
47
+ version: 0.2.1
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: 0.3.0
54
+ version: 0.2.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -103,10 +103,12 @@ files:
103
103
  - README.md
104
104
  - Rakefile
105
105
  - bin/fbup
106
+ - config/leagues.csv
106
107
  - config/openfootball.csv
107
108
  - lib/fbup.rb
108
109
  - lib/fbup/github.rb
109
110
  - lib/fbup/github_config.rb
111
+ - lib/fbup/league_config.rb
110
112
  - lib/fbup/main.rb
111
113
  - lib/fbup/version.rb
112
114
  homepage: https://github.com/sportdb/sport.db