23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
# File 'lib/fbtxt-pp/tool-fbhub.rb', line 23
def self.main( args=ARGV )
opts = {
push: false,
ffwd: false,
full: true, test: true, test_dir: './o',
convert_dir: '/sports/cache.api.fifa',
file: nil,
}
parser = OptionParser.new do |parser|
parser.banner = "Usage: #{$PROGRAM_NAME} [options] [args]"
parser.on( "-p", "--[no-]push",
"fast forward sync and commit & push changes to git repo - default is (#{opts[:push]})" ) do |push|
opts[:push] = push
if opts[:push] opts[:ffwd] = true
opts[:test] = false
end
end
parser.on( "-t", "--test",
"test run; writing output to #{opts[:test_dir]} - default is #{opts[:test]}" ) do |test|
opts[:test] = true
opts[:push] = false
opts[:ffwd] = false
end
parser.on( "-f FILE", "--file FILE",
"read leagues (and seasons) via .csv file") do |file|
opts[:file] = file
end
end
parser.parse!( args )
puts "OPTS:"
pp opts
datasets = if opts[:file]
recs = read_csv( opts[:file] )
datasets = recs.map do |rec|
[ rec['league'],
Season.parse_line( rec['seasons'])]
end
else
puts "!! error: --file FILE option for now required; sorry"
exit 1
end
pp datasets
root_dir = if opts[:test]
opts[:test_dir]
else
Fbup::GitHubSync.root end
puts " (output) root_dir: >#{root_dir}<"
repos = Fbup::GitHubSync.find_repos( datasets )
puts " #{repos.size} repo(s):"
pp repos
sync = Fbup::GitHubSync.new( repos )
puts " sync:"
pp sync
sync.git_fast_forward_if_clean if opts[:ffwd]
datasets.each do |slug, seasons|
puts "==> gen #{slug} - #{seasons.size} seasons(s)..."
config = CONFIGS[ slug ]
if config.nil?
puts "!! no pp config found for slug >#{slug}<; keys/codes include:"
pp CONFIGS.keys
exit 1
end
seasons.each do |season|
repo = Fbup::GitHubSync::REPOS[ slug ]
flags = repo['flags'] || {}
classic_flag = flags['classic'] || false
pp repo
basename = nil
if classic_flag
league_config = Fbup::LeagueConfig.find_by( code: LEAGUE_CODES[slug]||slug,
season: season )
if league_config.nil?
puts "!! ERROR - basename league config required for classic format; no config found for #{league_query} #{season}; sorry"
exit 1
end
basename = league_config['basename']
else
basename = (LEAGUE_CODES[slug]||slug).gsub( '.', '' )
end
repo_path = "#{repo['owner']}/#{repo['name']}"
repo_path << "/#{repo['path']}" if repo['path']
outpath = "#{root_dir}/#{repo_path}"
outpath += if classic_flag
"/#{season.to_path}/#{basename}.txt"
else
"/#{season.to_path}_#{basename}.txt"
end
outpath_full = "#{root_dir}/#{repo_path}"
outpath_full += if classic_flag
"/#{season.to_path}/#{basename}-full.txt"
else
"/#{season.to_path}_#{basename}-full.txt"
end
puts " writing to >#{outpath}<..."
puts " writing (full) to >#{outpath_full}<..."
league_name = config[:name]
format_opts = config[:opts]
format_opts_full = config[:opts_full]
= String.new
<< "= #{league_name} #{season}\n\n"
buf = pp_matches( slug: slug, season: season,
indir: opts[:convert_dir],
opts: FormatOpts.build( **format_opts ))
puts buf[0..300]
write_text( outpath, +buf )
if opts[:full]
buf = pp_matches_full( slug: slug, season: season,
indir: opts[:convert_dir],
opts: FormatOpts.build_full( **format_opts_full ))
puts buf[0..300]
write_text( outpath_full, +buf )
end
end
end
sync.git_push_if_changes if opts[:push]
puts "bye"
end
|