worldfootball 0.3.0 → 0.3.2

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: 89d825112036b8740d446612f179f44d96d33fbba1874ab51d8f9e5dda1e01a9
4
- data.tar.gz: 38d332b34ef4adb9017cbcee8434aa2f85d8a53a46e4556a267cb45443e17abd
3
+ metadata.gz: e84b891950ee051be8ef6ac91b8783f66ded443013729773c6a56af1e57a496c
4
+ data.tar.gz: 1c0dacfecd6f124b11829b5dee118a3937f48da67072fa5ad09b4fdcbd1a459b
5
5
  SHA512:
6
- metadata.gz: cf178997ed45d02f06e1039bab38d84979ab6df75422d73988c7dc2617d1a1cd4538f4ab5884ad4479faa130bd8203d8b58938f09fec661b937396cbc7364146
7
- data.tar.gz: 23e76db98b915fe5f280653d4928cfb7f6c7e1c8adbc506b7ae87ad6ba99fcb30748968111bcb0b6e24c545ee89d42906abc662d07440f6aad87227aac8cdda2
6
+ metadata.gz: ea8e5b931a08163bd30303cad79e8d0d3ec9a6b4aabed00a9638a2a77fc33aa8887646214c965404d2e938050200aaa5e854c7a87c0f79d6b9c8a7f3561d9601
7
+ data.tar.gz: 347feb8a6fd95541d73611b328d2608d021d8d06d4549f16ab5f5e2405537d8320e8d9b78bda7e645e9916ec77685849c87968adfd97534efed0d350a1d757ee
data/CHANGELOG.md CHANGED
@@ -1,5 +1,4 @@
1
- ### 0.3.0
2
-
1
+ ### 0.3.2
3
2
  ### 0.0.1 / 2024-07-04
4
3
 
5
4
  * Everything is new. First release.
data/Manifest.txt CHANGED
@@ -3,6 +3,12 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  bin/wfb
6
+ bin/wfbconf
7
+ bin/wfbconv
8
+ bin/wfbdump
9
+ bin/wfbgen
10
+ bin/wfbsync
11
+ bin/wfbup
6
12
  config/leagues/africa.csv
7
13
  config/leagues/america.csv
8
14
  config/leagues/asia.csv
data/README.md CHANGED
@@ -39,14 +39,56 @@ and so on.
39
39
 
40
40
 
41
41
 
42
- ### More
42
+ ### More Command-Line Tools
43
43
 
44
+ <!--
44
45
  Debugging tips & tricks. List all cached (offline local) match schedule pages:
45
46
 
46
47
  ```
47
48
  $ wfb cache
48
49
  ```
50
+ -->
49
51
 
52
+ wfbup -
53
+ wfbconv -
54
+ wfbgen -
55
+ wfbconf -
56
+ wfbdump
57
+
58
+
59
+ #### wfbup - download leagues (if no league passed in, download all!)
60
+
61
+ ```
62
+ $ wfbup # download ALL leagues and ALL seasons (uses all built-in configs)
63
+ $ wfbup at.1 # download ALL seasons for league
64
+ ```
65
+
66
+ #### wfbconv - convert (to .csv) leagues (if no league passed in, converts all!)
67
+
68
+ ```
69
+ $ wfbconv # convert ALL leagues and ALL seasons (uses all built-in configs)
70
+ $ wfbconv at.1 # convert ALL seasons for league
71
+ ```
72
+
73
+ #### wfbgen - generate (.txt) leagues (if no league passed in, generate all!)
74
+
75
+ ```
76
+ $ wfbgen # generate ALL leagues and ALL seasons (uses all built-in configs)
77
+ $ wfbgen at.1 # generate ALL seasons for league
78
+ ```
79
+
80
+
81
+ #### wfbconf - check built-in config(uration) for league
82
+
83
+ ```
84
+ $ wfbconf eng.1
85
+ ```
86
+
87
+ #### wfbdump - dump (page) slug incl. matches, teams, rounds & more
88
+
89
+ ```
90
+ $ wfbdump aut-bundesliga-2024-2025
91
+ ```
50
92
 
51
93
 
52
94
 
data/bin/wfb CHANGED
@@ -4,8 +4,12 @@
4
4
  ## ruby -I ./lib bin/wfb
5
5
  ## or
6
6
  ## ruby -I wfb/lib wfb/bin/wfb
7
+ ## or
8
+ ## ruby -I wfb/lib wfb/bin/wfb -f max.csv --cached
7
9
 
8
10
 
11
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/timezones/lib' )
12
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
9
13
  require 'worldfootball'
10
14
 
11
15
 
@@ -25,7 +29,7 @@ Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb')
25
29
  end
26
30
 
27
31
  Worldfootball.config.generate.out_dir = if File.exist?( '/sports/cache.wfb.txt')
28
- puts " setting convert out_dir to >/sports/cache.wfb.txt<"
32
+ puts " setting generate out_dir to >/sports/cache.wfb.txt<"
29
33
  '/sports/cache.wfb.txt'
30
34
  else
31
35
  './tmp' ## use tmp in working dir
@@ -35,6 +39,7 @@ Worldfootball.config.generate.out_dir = if File.exist?( '/sports/cache.wfb.txt')
35
39
  require 'optparse'
36
40
 
37
41
 
42
+
38
43
  module Worldfootball
39
44
  def self.main( args=ARGV )
40
45
 
@@ -130,15 +135,14 @@ end
130
135
  # assume leagues
131
136
 
132
137
  datasets = if opts[:file]
133
- read_datasets( opts[:file] )
138
+ read_leagueset( opts[:file] )
134
139
  else
135
- parse_datasets_args( args )
140
+ parse_leagueset_args( args )
136
141
  end
137
142
 
138
143
 
139
144
  ## step 0 - validate and fill-up seasons etc.
140
- datasets.each do |dataset|
141
- league_key, seasons = dataset
145
+ datasets.each do |league_key, seasons|
142
146
 
143
147
  league = find_league!( league_key ) ## league info lookup
144
148
 
@@ -150,8 +154,8 @@ datasets.each do |dataset|
150
154
  ## might be 2024/25 or 2024 or
151
155
  # for world cup 2022 or such
152
156
  if seasons.empty?
153
- seasons = [Season(league.seasons.keys[0])]
154
- dataset[1] = seasons
157
+ season = Season(league.seasons.keys[0])
158
+ seasons << season
155
159
  end
156
160
  end
157
161
 
@@ -206,36 +210,13 @@ if opts[:convert]
206
210
  end
207
211
  end
208
212
 
213
+
209
214
  if opts[:generate]
210
215
  ## step 3 - generate
211
216
  datasets.each do |league_key, seasons|
212
217
  seasons.each do |season|
213
-
214
- path = "#{config.convert.out_dir}/#{season.to_path}/#{league_key}.csv"
215
- ## get matches
216
- puts " ---> reading matches in #{path} ..."
217
- matches = SportDb::CsvMatchParser.read( path )
218
- puts " #{matches.size} matches"
219
-
220
- ## build
221
- txt = SportDb::TxtMatchWriter.build( matches )
222
- puts txt
223
-
224
- path = if season >= Season( '2000' )
225
- "#{config.generate.out_dir}/#{season.to_path}/#{league_key}.txt"
226
- else
227
- decade = season.start_year - (season.start_year%10)
228
- ## use archive-style before 2000!!!
229
- "#{config.generate.out_dir}/archive/#{decade}s/#{season.to_path}/#{league_key}.txt"
230
- end
231
-
232
- buf = String.new
233
- ## note - use league key for league name for now!!
234
- buf << "= #{league_key.upcase.gsub('.', ' ')} #{season.key}\n\n"
235
- buf << txt
236
-
237
- puts " writing to >#{path}<..."
238
- write_text( path, buf )
218
+ generate( league: league_key,
219
+ season: season )
239
220
  end
240
221
  end
241
222
  ## for debugging dump page (slug) titles
data/bin/wfbconf ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## tip: to test run:
4
+ ## ruby -I ./lib bin/wfbconf
5
+ ## or
6
+ ## ruby -I wfb/lib wfb/bin/wfbconf
7
+
8
+ ####
9
+ # wfbconf - check built-in config(uration) for league
10
+ # e.g. wfbconf eng.1
11
+
12
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
13
+ require 'worldfootball'
14
+
15
+
16
+ Webcache.root = if File.exist?( '/sports/cache' )
17
+ puts " setting web cache to >/sports/cache<"
18
+ '/sports/cache'
19
+ else
20
+ './cache'
21
+ end
22
+
23
+
24
+
25
+ require 'optparse'
26
+
27
+ ##
28
+ # by default convert all with overwrite/force set to false
29
+
30
+ Webget.config.sleep = 2
31
+
32
+ args = ARGV
33
+
34
+
35
+ Worldfootball.debug = true
36
+
37
+
38
+ if args.size == 0 ## no args; print all keys
39
+ keys = Worldfootball::LEAGUES.keys
40
+
41
+ pp keys
42
+ puts " #{keys.size} league(s)"
43
+ else
44
+ ##
45
+ ## download fresh copy?
46
+ ## Worldfootball::Metal.download_schedule( slug )
47
+
48
+ key = args[0] || 'eng.1'
49
+
50
+ league = Worldfootball::LEAGUES[key]
51
+ seasons = league.seasons
52
+ pp seasons
53
+
54
+ puts " #{key} - #{seasons.size} season(s)"
55
+
56
+ puts
57
+ latest = seasons.keys[0]
58
+ puts " latest #{latest}: "
59
+ pp seasons[latest]
60
+ end
61
+
62
+
63
+ puts "bye"
data/bin/wfbconv ADDED
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## tip: to test run:
4
+ ## ruby -I ./lib bin/wfbconv
5
+ ## or
6
+ ## ruby -I wfb/lib wfb/bin/wfbconv
7
+
8
+ ###
9
+ # wfbconv - convert (to .csv) all leagues (if no league passed in, converts all!)
10
+ #
11
+
12
+
13
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/timezones/lib' )
14
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
15
+ require 'worldfootball'
16
+
17
+
18
+ Webcache.root = if File.exist?( '/sports/cache' )
19
+ puts " setting web cache to >/sports/cache<"
20
+ '/sports/cache'
21
+ else
22
+ './cache'
23
+ end
24
+
25
+ ## convert (default) output directory
26
+ Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb')
27
+ puts " setting convert out_dir to >/sports/cache.wfb<"
28
+ '/sports/cache.wfb'
29
+ else
30
+ './tmp' ## use tmp in working dir
31
+ end
32
+
33
+ Worldfootball.config.generate.out_dir = if File.exist?( '/sports/cache.wfb.txt')
34
+ puts " setting generate out_dir to >/sports/cache.wfb.txt<"
35
+ '/sports/cache.wfb.txt'
36
+ else
37
+ './tmp' ## use tmp in working dir
38
+ end
39
+
40
+
41
+ require 'optparse'
42
+
43
+ ##
44
+ # by default convert all with overwrite/force set to false
45
+
46
+ Webget.config.sleep = 2
47
+
48
+ args = ARGV
49
+
50
+ opts = {
51
+ force: false, # a.k.a. overwrite
52
+ }
53
+
54
+
55
+ parser = OptionParser.new do |parser|
56
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
57
+
58
+
59
+ parser.on( "--force",
60
+ "always overwrite (force) datafile - default is (#{opts[:force]})" ) do |force|
61
+ opts[:force] = true # true|false
62
+ end
63
+ end
64
+
65
+
66
+ parser.parse!( args )
67
+
68
+ puts "OPTS:"
69
+ p opts
70
+ puts "ARGV:"
71
+ p args
72
+
73
+
74
+ keys = if args.size == 0
75
+ Worldfootball::LEAGUES.keys
76
+ else
77
+ args
78
+ end
79
+
80
+
81
+
82
+ keys.each_with_index do |key, i|
83
+ league = Worldfootball::LEAGUES[key]
84
+ seasons = league.seasons
85
+
86
+ puts "==> #{i+1}/#{keys.size} #{key} - #{seasons.size} seasons(s)..."
87
+
88
+ seasons.each_with_index do |season_rec,j|
89
+ season = season_rec[0]
90
+
91
+ next if key == 'nl.cup' && season == '1959/60'
92
+
93
+ puts " #{j+1}/#{seasons.size} #{key} #{season}..."
94
+ Worldfootball.convert( league: key, season: season,
95
+ overwrite: opts[:force] )
96
+ end
97
+ end
98
+
99
+
100
+ puts "bye"
data/bin/wfbdump ADDED
@@ -0,0 +1,76 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## tip: to test run:
4
+ ## ruby -I ./lib bin/wfbdump
5
+ ## or
6
+ ## ruby -I wfb/lib wfb/bin/wfbdump
7
+
8
+
9
+ #####
10
+ # wfbdump - dump matches, teams, rounds and more for (page) slug
11
+ # e.g.
12
+ # wfbdump caf-champions-league-2008
13
+ # wfbdump aut-bundesliga-2024-2025
14
+
15
+
16
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
17
+ require 'worldfootball'
18
+
19
+
20
+ Webcache.root = if File.exist?( '/sports/cache' )
21
+ puts " setting web cache to >/sports/cache<"
22
+ '/sports/cache'
23
+ else
24
+ './cache'
25
+ end
26
+
27
+
28
+
29
+ require 'optparse'
30
+
31
+ ##
32
+ # by default convert all with overwrite/force set to false
33
+
34
+ Webget.config.sleep = 2
35
+
36
+ args = ARGV
37
+
38
+
39
+ Worldfootball.debug = true
40
+
41
+ ##
42
+ ## download fresh copy?
43
+ ## Worldfootball::Metal.download_schedule( slug )
44
+
45
+ slug = args[0] || 'caf-champions-league-2008'
46
+
47
+ page = Worldfootball::Page::Schedule.from_cache( slug )
48
+
49
+ matches = page.matches
50
+ teams = page.teams
51
+ rounds = page.rounds
52
+
53
+ puts " #{matches.size} match(es), #{teams.size} team(s), #{rounds.size} round(s)"
54
+ # pp matches
55
+
56
+ puts
57
+ puts " #{teams.size} team(s)"
58
+ pp teams
59
+
60
+ puts
61
+ puts " #{rounds.size} round(s)"
62
+ pp rounds
63
+
64
+
65
+ puts "==> page props"
66
+ print "title: "
67
+ puts page.title
68
+ puts
69
+ print "keywords: "
70
+ puts page.keywords
71
+ puts
72
+ print "url: "
73
+ puts page.url
74
+
75
+
76
+ puts "bye"
data/bin/wfbgen ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ## tip: to test run:
4
+ ## ruby -I ./lib bin/wfbgen
5
+ ## or
6
+ ## ruby -I wfb/lib wfb/bin/wfbgen
7
+
8
+ ###############
9
+ # wfbgen
10
+ #
11
+
12
+
13
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/timezones/lib' )
14
+ $LOAD_PATH.unshift( '/sports/sportdb/sportdb-writers/lib' )
15
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
16
+
17
+ require 'worldfootball'
18
+
19
+
20
+ Webcache.root = if File.exist?( '/sports/cache' )
21
+ puts " setting web cache to >/sports/cache<"
22
+ '/sports/cache'
23
+ else
24
+ './cache'
25
+ end
26
+
27
+ ## convert (default) output directory
28
+ Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb')
29
+ puts " setting convert out_dir to >/sports/cache.wfb<"
30
+ '/sports/cache.wfb'
31
+ else
32
+ './tmp' ## use tmp in working dir
33
+ end
34
+
35
+ Worldfootball.config.generate.out_dir = if File.exist?( '/sports/cache.wfb.txt')
36
+ puts " setting generate out_dir to >/sports/cache.wfb.txt<"
37
+ '/sports/cache.wfb.txt'
38
+ else
39
+ './tmp' ## use tmp in working dir
40
+ end
41
+
42
+
43
+ require 'optparse'
44
+
45
+ ##
46
+ # by default convert all with overwrite/force set to false
47
+
48
+ Webget.config.sleep = 2
49
+
50
+ args = ARGV
51
+
52
+ opts = {
53
+ force: false, # a.k.a. overwrite
54
+ }
55
+
56
+
57
+ parser = OptionParser.new do |parser|
58
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
59
+
60
+
61
+ parser.on( "--force",
62
+ "always overwrite (force) datafile - default is (#{opts[:force]})" ) do |force|
63
+ opts[:force] = true # true|false
64
+ end
65
+ end
66
+
67
+
68
+ parser.parse!( args )
69
+
70
+ puts "OPTS:"
71
+ p opts
72
+ puts "ARGV:"
73
+ p args
74
+
75
+
76
+ keys = if args.size == 0
77
+ Worldfootball::LEAGUES.keys
78
+ else
79
+ args
80
+ end
81
+
82
+
83
+
84
+ keys.each_with_index do |key, i|
85
+ league = Worldfootball::LEAGUES[key]
86
+ seasons = league.seasons
87
+
88
+ puts "==> #{i+1}/#{keys.size} #{key} - #{seasons.size} seasons(s)..."
89
+
90
+ seasons.each_with_index do |season_rec,j|
91
+ season = season_rec[0]
92
+
93
+ next if key == 'nl.cup' && season == '1959/60'
94
+
95
+ puts " #{j+1}/#{seasons.size} #{key} #{season}..."
96
+ Worldfootball.generate( league: key, season: season,
97
+ overwrite: opts[:force] )
98
+ end
99
+ end
100
+
101
+
102
+ puts "bye"