sportdb-writers 0.2.3 → 0.3.0

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: 7e39ff7eabe3ea46542b2578b6b16e78898c78fe050f51b8144edd58ca4db6cf
4
- data.tar.gz: 5b7217690f74688ea6e58be0471a2469b384da68c2d11a26aaceb8b0dd0a2e89
3
+ metadata.gz: 10b19eac6f6a70a144de7201b0b72f60628e169e91ca51880cfde5bcc6b52690
4
+ data.tar.gz: 371f70efc9ffb6fd2ce77eb8087acfbdda68b2ced50019a3fd85ce9582331104
5
5
  SHA512:
6
- metadata.gz: c2f423732fe974d9e6f422a2d1b5b511d67596e5ceaab96a812d2774008f86cc1b94a23c793c12c0b9a058f1a208d2ffc554ae7761777b719d679e1804a9bf91
7
- data.tar.gz: e3ae9cf74f038df21a3f3275a03758eae2b1b110ec8571ed6fa6dd17cf4804eb5b34e6037ac85bbfe94a64b9f3645c0b9e8d6c8e67da11cf4f083f34e3417cb4
6
+ metadata.gz: 69d5f4ce4d13bdb73c3b5a96fd92583f043c15fecaa2209ffa81c56c4204adfb3d042b25edfd28e19c8cf89461d01f5847d563819841d8fb810d1673de15784b
7
+ data.tar.gz: cfb92a600bafc109e13f12bf8d513be4ce3003b358aef32581a9880719a47644d9308d129c8e808c39a1678d065789cfc0ed2bd4a3f57f5f8f0c00691ddb11f5
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 0.2.3
1
+ ### 0.3.0
2
2
 
3
3
  ### 0.0.1 / 2020-11-15
4
4
 
data/Manifest.txt CHANGED
@@ -4,16 +4,11 @@ README.md
4
4
  Rakefile
5
5
  bin/fbgen
6
6
  bin/fbtxt
7
- bin/fbup
8
7
  config/leagues_america.csv
9
8
  config/leagues_europe.csv
10
9
  config/leagues_world.csv
11
- config/openfootball.csv
12
10
  lib/sportdb/fbgen/main.rb
13
11
  lib/sportdb/fbtxt/main.rb
14
- lib/sportdb/fbup/github.rb
15
- lib/sportdb/fbup/github_config.rb
16
- lib/sportdb/fbup/main.rb
17
12
  lib/sportdb/writers.rb
18
13
  lib/sportdb/writers/goals.rb
19
14
  lib/sportdb/writers/league_config.rb
data/README.md CHANGED
@@ -4,7 +4,6 @@
4
4
  * bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
5
5
  * gem :: [rubygems.org/gems/sportdb-writers](https://rubygems.org/gems/sportdb-writers)
6
6
  * rdoc :: [rubydoc.info/gems/sportdb-writers](http://rubydoc.info/gems/sportdb-writers)
7
- * forum :: [groups.google.com/group/opensport](https://groups.google.com/group/opensport)
8
7
 
9
8
 
10
9
 
data/Rakefile CHANGED
@@ -20,7 +20,6 @@ Hoe.spec 'sportdb-writers' do
20
20
  self.extra_deps = [
21
21
  ['football-timezones'],
22
22
  ['sportdb-quick'],
23
- ['gitti'],
24
23
  ]
25
24
 
26
25
  self.licenses = ['Public Domain']
@@ -1,8 +1,21 @@
1
1
  key, name, basename, start_season, end_season, comments
2
2
 
3
3
  ar.1, Argentina Primera Division, 1-primeradivision,,,
4
+
4
5
  br.1, Brasileiro Série A, 1-seriea,,,
5
- br.2, Brasileiro Série B, 1-serieb,,,
6
+ br.2, Brasileiro Série B, 2-serieb,,,
7
+ br.3, Brasileiro Série C, 3-seriec,,,
8
+ br.4, Brasileiro Série D, 4-seried,,,
9
+ br.cup, Copa do Brasil, cup,,,
10
+
11
+ br.carioca, Campeonato Carioca, carioca,,,
12
+ br.gauchao, Campeonato Gaúcho, gauchao,,,
13
+ br.mineiro, Campeonato Mineiro, mineiro,,,
14
+ br.paranaense, Campeonato Paranaense, paranaense,,,
15
+ br.paulistao, Campeonato Paulista, paulistao,,,
16
+
17
+ co.1, Colombia Primera A, 1-primeraa,,,
18
+
6
19
 
7
20
  copa.l, Copa Libertadores, libertadores,,,
8
21
  copa.s, Copa Sudamericana, sudamericana,,,
@@ -3,7 +3,8 @@ key, name, basename, start_season, end_season, co
3
3
  at.1, Österr. Bundesliga, 1-bundesliga,,,
4
4
  at.2, Österr. 2. Liga, 2-liga2, 2018/19,,
5
5
  at.2, Österr. Erste Liga, 2-liga1, , 2017/18,
6
- at.3.o, Österr. Regionalliga Ost, 3-regionalliga-ost,,,
6
+ at.3.o, Österr. Regionalliga Ost, 3-regionalliga-ost,,,
7
+ at.3.m, Österr. Regionalliga Mitte, 3-regionalliga-mitte,,,
7
8
  at.cup, ÖFB Cup, cup,,,
8
9
 
9
10
 
@@ -21,27 +22,44 @@ de.cup, DFB Pokal, cup,,,
21
22
 
22
23
  it.1, Italian Serie A, 1-seriea,,,
23
24
  it.2, Italian Serie B, 2-serieb,,,
25
+ it.cup, Coppa Italia, cup,,,
26
+
24
27
 
25
28
  es.1, Primera División de España, 1-liga,,,
26
29
  es.2, Segunda División de España, 2-liga2,,,
30
+ es.cup, Copa del Rey de España, cup,,,
31
+
27
32
 
28
33
  fr.1, French Ligue 1, 1-ligue1,,,
29
34
  fr.2, French Ligue 2, 2-ligue2,,,
30
35
 
31
36
 
32
- eng.1, English Premier League, 1-premierleague, 1992/93,,
33
- eng.1, English Division One, 1-division1, 1892/93, 1991/92, ## start of division 1 & 2
34
- eng.1, English Football League, 1-footballleague, 1888/89, 1891/92, ## single league (no divisions)
37
+ ##
38
+ ## note - starting with the 2004/05 season
39
+ # the Football League's Division 1, Division 2 and Division 3
40
+ ## changed to Championship, League One and League Two.
35
41
 
36
42
  eng.2, English Championship, 2-championship, 2004/05,, ## rebranding divsion 1 => championship
43
+ eng.3, English League One, 3-league1, 2004/05,,
44
+ eng.4, English League Two, 4-league2, 2004/05,,
45
+
46
+ eng.1, English Premier League, 1-premierleague, 1992/93,,
37
47
  eng.2, English Division One, 2-division1, 1992/93, 2003/04, ## start of premier league
48
+ eng.3, English Division Two, 3-division2, 1992/93, 2003/04,
49
+ eng.4, English Division Three, 4-division3, 1992/93, 2003/04,
50
+ eng.5, English National League, 5-nationalleague, 1992/93,,
51
+
52
+ eng.1, English Division One, 1-division1, 1892/93, 1991/92, ## start of division 1 & 2
38
53
  eng.2, English Division Two, 2-division2, 1892/93, 1991/92, ## or use English Football League Second Division ???
54
+ eng.3, English Division Three, 3-division3, , 1991/92,
55
+
56
+ eng.1, English Football League, 1-footballleague, 1888/89, 1891/92, ## single league (no divisions)
57
+
39
58
 
40
- eng.3, English League One, 3-league1,,,
41
- eng.4, English League Two, 4-league2,,,
42
- eng.5, English National League, 5-nationalleague,,,
43
59
  eng.cup, English FA Cup, facup,,,
44
60
 
61
+ wal.1, Welsh Premier League, 1-premierleague,,,
62
+ nir.1, Northern Irish Premiership, 1-premiership,,,
45
63
 
46
64
  hu.1, Hungarian NB I, 1-nbi,,,
47
65
 
@@ -91,14 +109,52 @@ ua.1, Ukraine Premier League, 1-premierleague,,,
91
109
  ru.1, Russian Premier League, 1-premierliga,,,
92
110
  ru.2, Russian 1. Division, 2-division1,,,
93
111
 
112
+ by.1, Belarusian Premier League, 1-premierleague,,,
113
+
114
+ al.1, Albanian Super League, 1-superleague,,,
115
+ ad.1, Andorran Premier Division, 1-premierdisvision,,,
116
+
117
+ ba.1, Bosnian-Herzegovinian Premier League, 1-premierleague,,,
118
+ bg.1, Bulgarian A League, 1-aleague,,,
119
+
120
+ cy.1, Cypriot First Division, 1-firstdivision,,,
121
+
122
+ ee.1, Estonian First League, 1-firstleague,,,
123
+ lv.1, Latvian First Division, 1-firstdivision,,,
124
+ lt.1, Lithuanian First Division, 1-firstdivision,,,
125
+
126
+ li.cup, Liechtensteiner Cup, cup,,,
127
+
128
+ mk.1, Macedonian First League, 1-firstleague,,,
129
+ mt.1, Macedonian First League, 1-firstleague,,,
130
+ md.1, Moldovan First Division, 1-firstdivision,,,
131
+ me.1, Montenegrin First League, 1-firstleague,,,
132
+
133
+ sm.1, San Marinese Championship, 1-championship,,,
134
+ rs.1, Serbian Super League, 1-superleague,,,
135
+ si.1, Slovene First League, 1-firstleague,,,
136
+
137
+ kos.1, Kosovan Superliga, 1-superliga,,,
138
+ xk.1, Kosovan Superliga, 1-superliga,,,
139
+
140
+ am.1, Armenian Premier League, 1-premierleague,,,
141
+ az.1, Azerbaijani Premier League, 1-premierleague,,,
142
+ ge.1, Georgian Premier League, 1-premierleague,,,
143
+
144
+ fo.1, Faroese Premier Division, 1-premierdivision,,,
145
+ gi.1, Gibraltarian Premier League, 1-premierleague,,,
146
+
94
147
 
95
148
 
96
149
  ## use uefa.1 - why? why not?
97
150
  ## uefa.2,
98
151
  ## uefa.3
99
152
  uefa.cl, UEFA Champions League, cl,,, ### use champs or such?
100
- uefa.el, UEFA Europa League, el,,, ### use europa
153
+ uefa.champs, UEFA Champions League, champs,,,
154
+ uefa.el, UEFA Europa League, el,,, ### use europa?
155
+ uefa.europa, UEFA Europa League, europa,,,
101
156
  uefa.conf, UEFA Conference League, conf,,, ### use con (conf - confusion with config files?)
157
+ uefa.con, UEFA Conference League, con,,,
102
158
 
103
159
  uefa.nl, UEFA Nations League, nl,,,
104
160
  euro, Euro, euro,,,
@@ -5,4 +5,19 @@ jp.1, Japan J1 League, 1-j1league,,,
5
5
 
6
6
 
7
7
 
8
- world, World Cup, cup,,,
8
+ kz.1, Kazakh Premier League, 1-premierleague,,,
9
+
10
+
11
+ il.1, Israeli Premier League, 1-premierleague,,,
12
+
13
+
14
+ eg.1, Egypt Premiership, 1-premiership,,,
15
+ ma.1, Morocco Botola Pro 1, 1-botolapro1,,,
16
+ dz.1, Algeria Ligue 1, 1-ligue1,,,
17
+
18
+ afl, African Football League, afl,,,
19
+ caf.cl, CAF Champions League, cl,,,
20
+ caf.champs, CAF Champions League, champs,,, ## use alternate code - why? why not?
21
+
22
+
23
+ world, World Cup, cup,,,
@@ -3,8 +3,8 @@ module SportDb
3
3
  module Module
4
4
  module Writers
5
5
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 2
7
- PATCH = 3
6
+ MINOR = 3
7
+ PATCH = 0
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -56,83 +56,5 @@ require_relative 'fbgen/main'
56
56
 
57
57
 
58
58
 
59
- ########################
60
- # push & pull github scripts
61
- require 'gitti' ## note - requires git machinery
62
-
63
- require_relative 'fbup/github_config'
64
- require_relative 'fbup/github' ## github helpers/update machinery
65
-
66
-
67
- module Fbup
68
- class GitHubSync
69
- REPOS = GitHubConfig.new
70
- recs = read_csv( "#{SportDb::Module::Writers.root}/config/openfootball.csv" )
71
- REPOS.add( recs )
72
-
73
- ## todo/check: find a better name for helper?
74
- ## note: datasets of format
75
- ##
76
- ## DATASETS = [
77
- ## ['it.1', %w[2020/21 2019/20]],
78
- ## ['it.2', %w[2019/20]],
79
- ## ['es.1', %w[2019/20]],
80
- ## ['es.2', %w[2019/20]],
81
- ## ]
82
-
83
- def self.find_repos( datasets )
84
- repos = []
85
- datasets.each do |dataset|
86
- league_key = dataset[0]
87
- repo = REPOS[ league_key ]
88
- ## pp repo
89
- if repo.nil?
90
- puts "!! ERROR - no repo config/path found for league >#{league_key}<; sorry"
91
- exit 1
92
- end
93
-
94
- repos << "#{repo['owner']}/#{repo['name']}"
95
- end
96
-
97
- pp repos
98
- repos.uniq ## note: remove duplicates (e.g. europe or world or such)
99
- end
100
- end # class GitHubSync
101
- end # module Fbup
102
-
103
-
104
- require_relative 'fbup/main'
105
-
106
-
107
-
108
- ###
109
- ## todo/fix: move more code into tool class or such? - why? why not?
110
-
111
- ## todo/check: find a better name for helper?
112
- ## find_all_datasets, filter_datatsets - add alias(es???
113
- ## queries (lik ARGV) e.g. ['at'] or ['eng', 'de'] etc. list of strings
114
- def filter_datasets( datasets, queries=[] )
115
- ## find all matching leagues (that is, league keys)
116
- if queries.empty? ## no filter - get all league keys
117
- datasets
118
- else
119
- datasets.find_all do |dataset|
120
- found = false
121
- ## note: normalize league key (remove dot and downcase)
122
- league_key = dataset[0].gsub( '.', '' )
123
- queries.each do |query|
124
- q = query.gsub( '.', '' ).downcase
125
- if league_key.start_with?( q )
126
- found = true
127
- break
128
- end
129
- end
130
- found
131
- end
132
- end
133
- end
134
-
135
-
136
-
137
59
 
138
60
  puts SportDb::Module::Writers.banner # say hello
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-writers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
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-16 00:00:00.000000000 Z
11
+ date: 2024-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: football-timezones
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: gitti
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: rdoc
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -92,7 +78,6 @@ email: gerald.bauer@gmail.com
92
78
  executables:
93
79
  - fbgen
94
80
  - fbtxt
95
- - fbup
96
81
  extensions: []
97
82
  extra_rdoc_files:
98
83
  - CHANGELOG.md
@@ -105,16 +90,11 @@ files:
105
90
  - Rakefile
106
91
  - bin/fbgen
107
92
  - bin/fbtxt
108
- - bin/fbup
109
93
  - config/leagues_america.csv
110
94
  - config/leagues_europe.csv
111
95
  - config/leagues_world.csv
112
- - config/openfootball.csv
113
96
  - lib/sportdb/fbgen/main.rb
114
97
  - lib/sportdb/fbtxt/main.rb
115
- - lib/sportdb/fbup/github.rb
116
- - lib/sportdb/fbup/github_config.rb
117
- - lib/sportdb/fbup/main.rb
118
98
  - lib/sportdb/writers.rb
119
99
  - lib/sportdb/writers/goals.rb
120
100
  - lib/sportdb/writers/league_config.rb
data/bin/fbup DELETED
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- ## tip: to test run:
4
- ## ruby -I ./lib bin/fbup
5
-
6
-
7
- require 'sportdb/writers'
8
-
9
-
10
- Fbup.main( ARGV )
11
-
12
-
13
- puts "bye"
@@ -1,67 +0,0 @@
1
- key, path
2
-
3
- at, austria
4
-
5
- de, deutschland
6
- eng, england
7
- es, espana
8
- it, italy
9
-
10
- fr, europe/france
11
-
12
- hu, europe/hungary
13
- gr, europe/greece
14
- pt, europe/portugal
15
-
16
- ch, europe/switzerland
17
-
18
- tr, europe/turkey
19
-
20
- is, europe/iceland
21
- sco, europe/scotland
22
- ie, europe/ireland
23
-
24
- fi, europe/finland
25
- se, europe/sweden
26
- no, europe/norway
27
- dk, europe/denmark
28
-
29
- lu, europe/luxembourg
30
- be, europe/belgium
31
- nl, europe/netherlands
32
- cz, europe/czech-republic
33
-
34
- sk, europe/slovakia
35
- hr, europe/croatia
36
- pl, europe/poland
37
-
38
- ro, europe/romania
39
-
40
- ua, europe/ukraine
41
-
42
- ru, europe/russia
43
-
44
-
45
- uefa.cl, europe-champions-league
46
- uefa.el, europe-champions-league
47
- uefa.conf, europe-champions-league
48
-
49
- euro, euro
50
-
51
-
52
-
53
- mx, mexico
54
-
55
-
56
- ar, south-america/argentina
57
- br, south-america/brazil
58
-
59
- copa.l, south-america/copa-libertadores
60
- copa.s, south-america/copa-libertadores
61
-
62
-
63
- cn, world/asia/china
64
- jp, world/asia/japan
65
-
66
-
67
- world, worldcup
@@ -1,83 +0,0 @@
1
-
2
- module Fbup
3
-
4
- ###
5
- ## todo/fix:
6
- ## add -i/--interactive flag
7
- ## will prompt yes/no before git operations (with consequences)!!!
8
-
9
-
10
-
11
- class GitHubSync
12
-
13
- ########
14
- ## (auto)default to Writer.config.out_dir - why? why not?
15
- ##
16
- ## note - is monotree (that is, requires openfootball/england etc.
17
- ## for repo pathspecs)
18
- def self.root() @root || "/sports"; end
19
- def self.root=( dir ) @root = dir; end
20
- ## use root_dir (alias) - why? why not?
21
-
22
-
23
- def initialize( repos )
24
- @repos = repos
25
- end
26
-
27
-
28
- def git_push_if_changes
29
- message = "auto-update week #{Date.today.cweek}" ## add /#{Date.today.cday - why? why not?
30
- puts message
31
-
32
- @repos.each do |pathspec|
33
- _git_push_if_changes( pathspec, message: message )
34
- end
35
- end
36
-
37
- def git_fast_forward_if_clean
38
- @repos.each do |pathspec|
39
- _git_fast_forward_if_clean( pathspec )
40
- end
41
- end
42
-
43
-
44
-
45
- ## todo/fix: rename to something like
46
- ## git_(auto_)commit_and_push_if_changes/if_dirty()
47
-
48
- def _git_push_if_changes( pathspec, message: )
49
- path = "#{self.class.root}/#{pathspec}"
50
-
51
- Gitti::GitProject.open( path ) do |proj|
52
- puts ''
53
- puts "###########################################"
54
- puts "## trying to commit & push repo in path >#{path}<"
55
- puts "Dir.getwd: #{Dir.getwd}"
56
- output = proj.changes
57
- if output.empty?
58
- puts "no changes found; skipping commit & push"
59
- else
60
- proj.add( '.' )
61
- proj.commit( message )
62
- proj.push
63
- end
64
- end
65
- end
66
-
67
-
68
- def _git_fast_forward_if_clean( pathspec )
69
- path = "#{self.class.root}/#{pathspec}"
70
-
71
- Gitti::GitProject.open( path ) do |proj|
72
- output = proj.changes
73
- unless output.empty?
74
- puts "FAIL - cannot git pull (fast-forward) - working tree has changes:"
75
- puts output
76
- exit 1
77
- end
78
-
79
- proj.fast_forward
80
- end
81
- end
82
- end # class GitHub
83
- end # module Fbup
@@ -1,97 +0,0 @@
1
-
2
- module Fbup
3
- class GitHubConfig
4
-
5
- ## map leagues to repo+path
6
- ## e.g. fr.1 => europe/france
7
- ## eng..1 => england
8
- ##
9
- ## for other than openfootball (default)
10
- ## use @
11
- ## e.g. myorg@austria
12
- ## austria@myorg ??
13
- ##
14
- ## myorg@europe/france
15
- ## europe/france@myorg
16
-
17
-
18
- def self.read( path )
19
- recs = read_csv( path )
20
- new( recs )
21
- end
22
-
23
- def initialize( recs=nil )
24
- @table = {}
25
- add( recs ) if recs
26
- end
27
-
28
-
29
- def add( recs )
30
- recs.each do |rec|
31
- path = rec['path'] ## use pathspec - why? why not?
32
- ## or repospec or such
33
-
34
- ## auto-expand to openfootball as default org if no @ specified
35
- owner, path = if path.index( '@')
36
- path.split( '@', 2 )
37
- else
38
- ['openfootball', path ]
39
- end
40
- name, path = path.split( '/', 2 )
41
-
42
-
43
- ## openfootball@europe/france
44
- ## =>
45
- ## owner: openfootball
46
- ## name: europe
47
- ## path: france
48
- ##
49
- ## openfootball@austria
50
- ## =>
51
- ## owner: openfootball
52
- ## name: austria
53
- ## path: nil
54
- @table[ rec['key'] ] = { 'owner' => owner, ## (required)
55
- 'name' => name, ## (required)
56
- 'path' => path ## extra/inner/inside/local path (optional)
57
- }
58
- end
59
- end
60
-
61
-
62
- ##
63
- ## todo/fix:
64
- ## make key lookup more flexible
65
- ## auto-add more variants!!!
66
- ## e.g. at.1 AT1, AT or such
67
- ##
68
-
69
- ## find (full) record by key
70
- def find( key )
71
- key = key.to_s.downcase
72
-
73
- ## first check for 1:1 match
74
- rec = @table[key]
75
- if rec.nil?
76
- ## try match by (country / first) code
77
- ## split by .
78
- key, _ = key.split( '.' )
79
- rec = @table[key]
80
- end
81
-
82
- rec
83
- end
84
- alias_method :[], :find ## keep alias - why? why not?
85
-
86
-
87
- def find_repo( key )
88
- rec = _find( key )
89
-
90
- rec ? "#{rec['owner']}/#{rec['name']}" : nil
91
- end
92
-
93
- end # class GitHubConfig
94
- end # module Fbup
95
-
96
-
97
-
@@ -1,162 +0,0 @@
1
-
2
- module Fbup
3
- def self.main( args=ARGV )
4
-
5
- opts = {
6
- source_path: [],
7
- push: false,
8
- ffwd: false,
9
- dry: false, ## dry run (no write)
10
- test: true, ## sets push & ffwd to false
11
- debug: true,
12
- file: nil,
13
- test_dir: './o',
14
- }
15
-
16
-
17
- parser = OptionParser.new do |parser|
18
- parser.banner = "Usage: #{$PROGRAM_NAME} [options] [args]"
19
-
20
- parser.on( "-p", "--[no-]push",
21
- "fast forward sync and commit & push changes to git repo - default is (#{opts[:push]})" ) do |push|
22
- opts[:push] = push
23
- if opts[:push] ## note: autoset ffwd too if push == true
24
- opts[:ffwd] = true
25
- opts[:test] = false
26
- end
27
- end
28
- ## todo/check - add a --ffwd flag too - why? why not?
29
-
30
- parser.on( "-t", "--test",
31
- "test run; writing output to #{opts[:test_dir]} - default is #{opts[:test]}" ) do |test|
32
- opts[:test] = true
33
- opts[:push] = false
34
- opts[:ffwd] = false
35
- end
36
- parser.on( "--dry",
37
- "dry run; do NOT write - default is (#{opts[:dry]})" ) do |dry|
38
- opts[:dry] = dry
39
- opts[:push] = false ### autoset push & ffwd - why? why not?
40
- opts[:ffwd] = false
41
- end
42
-
43
- parser.on( "-q", "--quiet",
44
- "less debug output/messages - default is (#{!opts[:debug]})" ) do |debug|
45
- opts[:debug] = false
46
- end
47
-
48
- parser.on( "-I DIR", "--include DIR",
49
- "add directory to (source) search path - default is (#{opts[:source_path].join(',')})") do |dir|
50
- opts[:source_path] += path
51
- end
52
-
53
- parser.on( "-f FILE", "--file FILE",
54
- "read leagues (and seasons) via .csv file") do |file|
55
- opts[:file] = file
56
- end
57
- end
58
- parser.parse!( args )
59
-
60
-
61
- if opts[:source_path].empty? &&
62
- File.exist?( '/sports/cache.api.fbdat') &&
63
- File.exist?( '/sports/cache.wfb' )
64
- opts[:source_path] << '/sports/cache.api.fbdat'
65
- opts[:source_path] << '/sports/cache.wfb'
66
- end
67
-
68
- if opts[:source_path].empty?
69
- opts[:source_path] = ['.'] ## use ./ as default
70
- end
71
-
72
-
73
-
74
- puts "OPTS:"
75
- p opts
76
- puts "ARGV:"
77
- p args
78
-
79
-
80
- datasets = if opts[:file]
81
- read_datasets( opts[:file] )
82
- else
83
- parse_datasets_args( args )
84
- end
85
-
86
- puts "datasets:"
87
- pp datasets
88
-
89
-
90
- source_path = opts[:source_path]
91
-
92
- root_dir = if opts[:test]
93
- opts[:test_dir]
94
- else
95
- GitHubSync.root # e.g. "/sports"
96
- end
97
-
98
- puts " (output) root_dir: >#{root_dir}<"
99
-
100
- repos = GitHubSync.find_repos( datasets )
101
- puts " #{repos.size} repo(s):"
102
- pp repos
103
- sync = GitHubSync.new( repos )
104
-
105
- puts " sync:"
106
- pp sync
107
-
108
-
109
- sync.git_fast_forward_if_clean if opts[:ffwd]
110
-
111
- ### step 0 - validate and fill-in seasons etc.
112
- ## reuse from Fbgen tool
113
- Fbgen.validate_datasets!( datasets, source_path: source_path )
114
-
115
-
116
- datasets.each do |league_key, seasons|
117
- puts "==> gen #{league_key} - #{seasons.size} seasons(s)..."
118
-
119
- league_info = Writer::LEAGUES[ league_key ]
120
- pp league_info
121
-
122
- seasons.each do |season|
123
- filename = "#{season.to_path}/#{league_key}.csv"
124
- path = Fbgen.find_file( filename, path: source_path )
125
-
126
- ### get matches
127
- puts " ---> reading matches in #{path} ..."
128
- matches = SportDb::CsvMatchParser.read( path )
129
- puts " #{matches.size} matches"
130
-
131
- ## build
132
- txt = SportDb::TxtMatchWriter.build( matches )
133
- puts txt if opts[:debug]
134
-
135
- league_name = league_info[ :name ] # e.g. Brasileiro Série A
136
- basename = league_info[ :basename] #.e.g 1-seriea
137
-
138
- league_name = league_name.call( season ) if league_name.is_a?( Proc ) ## is proc/func - name depends on season
139
- basename = basename.call( season ) if basename.is_a?( Proc ) ## is proc/func - name depends on season
140
-
141
- buf = String.new
142
- buf << "= #{league_name} #{season}\n\n"
143
- buf << txt
144
-
145
- repo = GitHubSync::REPOS[ league_key ]
146
- repo_path = "#{repo['owner']}/#{repo['name']}"
147
- repo_path << "/#{repo['path']}" if repo['path'] ## note: do NOT forget to add optional extra path!!!
148
-
149
- outpath = "#{root_dir}/#{repo_path}/#{season.to_path}/#{basename}.txt"
150
-
151
- if opts[:dry]
152
- puts " (dry) writing to >#{outpath}<..."
153
- else
154
- write_text( outpath, buf )
155
- end
156
- end
157
- end
158
-
159
- sync.git_push_if_changes if opts[:push]
160
-
161
- end # method self.main
162
- end # module Fbgen