worldfootball 0.2.6 → 0.3.1

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: 9d824bdedb279bf91779c99445fcf5bd5a6df8acc342232624032256a32fbe18
4
- data.tar.gz: 14eb224174efe18645412a88eaa332e01901247dd28ffa795cba8b902d3a1dd6
3
+ metadata.gz: 53f1c44ded1d0dcec880df13b61a77265febcceacd88acb5ce883db39914cce9
4
+ data.tar.gz: b56eb75f1277026f77c29ee8f4d51788978955accbac5812659d1f3597e9747f
5
5
  SHA512:
6
- metadata.gz: b0e4885e80c6ff3fb13a00a654524ea4514fcac730438096e412cd76a5ba14c17fa563996afd81176f7538bffb6ac8bdc3c75de7af7ace2124269b7c72c0265b
7
- data.tar.gz: feb02079e9c481c3b2e53d5c72030e5e9e687f94bf053c29134da613933c2f5f6b569339fb8980ab3c048e248c171c93ea23a4b4a350c5dfede8563990b5a298
6
+ metadata.gz: 501b137138a280f74d1cbd50c8f9ebc44ec8f1b7c7c9268005deb2d3a04b2d0046d05bf5a5ff7b3fb7c6f9f7b938423cdd83bb3b983d020bfb26057f2ed463c9
7
+ data.tar.gz: 84d716bcbffb32c11da5fd3a6b549a115ecbea0b4747182d84e3e7280cf3ff2de37ee57d37b20288d43f57374727fa907b256ed745b04d8b32b44ae17809d8ee
data/CHANGELOG.md CHANGED
@@ -1,5 +1,4 @@
1
- ### 0.2.6
2
-
1
+ ### 0.3.1
3
2
  ### 0.0.1 / 2024-07-04
4
3
 
5
4
  * Everything is new. First release.
data/Manifest.txt CHANGED
@@ -3,12 +3,17 @@ Manifest.txt
3
3
  README.md
4
4
  Rakefile
5
5
  bin/wfb
6
- config/leagues_africa.csv
7
- config/leagues_america.csv
8
- config/leagues_asia.csv
9
- config/leagues_europe.csv
10
- config/leagues_middle_east.csv
11
- config/leagues_pacific.csv
6
+ bin/wfbconf
7
+ bin/wfbconv
8
+ bin/wfbdump
9
+ bin/wfbgen
10
+ bin/wfbup
11
+ config/leagues/africa.csv
12
+ config/leagues/america.csv
13
+ config/leagues/asia.csv
14
+ config/leagues/europe.csv
15
+ config/leagues/middle_east.csv
16
+ config/leagues/pacific.csv
12
17
  config/rounds.csv
13
18
  config/stages.csv
14
19
  lib/worldfootball.rb
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # worldfootball - get world football (leagues, cups & more) match data via the worldfootball.net/weltfussball.de pages
2
-
2
+
3
3
 
4
4
  * home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
5
5
  * bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
@@ -39,14 +39,56 @@ and so on.
39
39
 
40
40
 
41
41
 
42
- ### More
42
+ ### More Command-Line Tools
43
43
 
44
- Debugging tips. List all cached (offline local) match schedule pages:
44
+ <!--
45
+ Debugging tips & tricks. List all cached (offline local) match schedule pages:
45
46
 
46
47
  ```
47
48
  $ wfb cache
48
49
  ```
50
+ -->
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!)
49
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/Rakefile CHANGED
@@ -22,6 +22,7 @@ Hoe.spec 'worldfootball' do
22
22
  ['fifa'],
23
23
  ['webget'],
24
24
  ['nokogiri'],
25
+ ['sportdb-writers'],
25
26
  ]
26
27
 
27
28
  self.licenses = ['Public Domain']
data/bin/wfb CHANGED
@@ -2,7 +2,14 @@
2
2
 
3
3
  ## tip: to test run:
4
4
  ## ruby -I ./lib bin/wfb
5
+ ## or
6
+ ## ruby -I wfb/lib wfb/bin/wfb
7
+ ## or
8
+ ## ruby -I wfb/lib wfb/bin/wfb -f max.csv --cached
5
9
 
10
+
11
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/timezones/lib' )
12
+ $LOAD_PATH.unshift( '/sports/sportdb/sport.db/fifa/lib' )
6
13
  require 'worldfootball'
7
14
 
8
15
 
@@ -18,19 +25,30 @@ Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb')
18
25
  puts " setting convert out_dir to >/sports/cache.wfb<"
19
26
  '/sports/cache.wfb'
20
27
  else
21
- '.' ## use working dir
28
+ './tmp' ## use tmp in working dir
29
+ end
30
+
31
+ Worldfootball.config.generate.out_dir = if File.exist?( '/sports/cache.wfb.txt')
32
+ puts " setting generate out_dir to >/sports/cache.wfb.txt<"
33
+ '/sports/cache.wfb.txt'
34
+ else
35
+ './tmp' ## use tmp in working dir
22
36
  end
23
37
 
38
+
24
39
  require 'optparse'
25
40
 
26
41
 
42
+
27
43
  module Worldfootball
28
44
  def self.main( args=ARGV )
29
45
 
30
46
  opts = {
31
- cached: false,
32
- convert: true,
33
- file: nil,
47
+ debug: false,
48
+ cached: false,
49
+ convert: true,
50
+ generate: true,
51
+ file: nil,
34
52
  }
35
53
 
36
54
 
@@ -49,14 +67,22 @@ parser = OptionParser.new do |parser|
49
67
  end
50
68
 
51
69
  parser.on( "--[no-]convert",
52
- "turn on/off conversion to .csv in #{Worldfootball.config.convert.out_dir} - default is (#{opts[:convert]})" ) do |convert|
70
+ "turn on/off conversion to (tabular) .csv format in #{Worldfootball.config.convert.out_dir} - default is (#{opts[:convert]})" ) do |convert|
53
71
  opts[:convert] = convert # true|false
54
72
  end
55
73
 
74
+ parser.on( "--[no-]generate",
75
+ "turn on/off generation in football.txt format in #{Worldfootball.config.generate.out_dir} - default is (#{opts[:generate]})" ) do |generate|
76
+ opts[:generate] = generate # true|false
77
+ end
78
+
79
+
56
80
  parser.on( "--print", "--pp",
57
- "pretty print cached data in #{Webcache.root}; no download & conversion") do |print|
58
- opts[:cached] = true
59
- opts[:convert] = false
81
+ "pretty print cached data in #{Webcache.root}; no download & conversion & generation") do |print|
82
+ opts[:debug] = true
83
+ opts[:cached] = true
84
+ opts[:convert] = false
85
+ opts[:generate] = false
60
86
  end
61
87
 
62
88
  parser.on( "-f FILE", "--file FILE",
@@ -76,6 +102,14 @@ puts "ARGV:"
76
102
  p args
77
103
 
78
104
 
105
+ ## turn on debug output
106
+ if opts[:debug]
107
+ Worldfootball.debug = true
108
+ else
109
+ Worldfootball.debug = false
110
+ end
111
+
112
+
79
113
  ### check special (built-in) commands first
80
114
  if ['cache'].include?( args[0] )
81
115
  Worldfootball.list_pages
@@ -101,15 +135,14 @@ end
101
135
  # assume leagues
102
136
 
103
137
  datasets = if opts[:file]
104
- read_datasets( opts[:file] )
138
+ read_leagueset( opts[:file] )
105
139
  else
106
- parse_datasets_args( args )
140
+ parse_leagueset_args( args )
107
141
  end
108
142
 
109
143
 
110
144
  ## step 0 - validate and fill-up seasons etc.
111
- datasets.each do |dataset|
112
- league_key, seasons = dataset
145
+ datasets.each do |league_key, seasons|
113
146
 
114
147
  league = find_league!( league_key ) ## league info lookup
115
148
 
@@ -121,12 +154,17 @@ datasets.each do |dataset|
121
154
  ## might be 2024/25 or 2024 or
122
155
  # for world cup 2022 or such
123
156
  if seasons.empty?
124
- seasons = [Season(league.seasons.keys[0])]
125
- dataset[1] = seasons
157
+ season = Season(league.seasons.keys[0])
158
+ seasons << season
126
159
  end
127
160
  end
128
161
 
129
162
 
163
+ ###
164
+ ## collect league names & more
165
+ extra = {}
166
+
167
+
130
168
  ## step 1 - download
131
169
  datasets.each do |league_key, seasons|
132
170
  league = find_league!( league_key ) ## league info lookup
@@ -152,6 +190,10 @@ datasets.each do |league_key, seasons|
152
190
  matches = page.matches
153
191
 
154
192
  puts " #{matches.size} match(es)"
193
+
194
+ league_extra = extra[ league.key ] ||= {}
195
+ season_extra = league_extra[ season.key] ||= { names: [] }
196
+ season_extra[:names] << page.title
155
197
  end
156
198
  end # each seasons
157
199
  end # each league
@@ -169,6 +211,20 @@ if opts[:convert]
169
211
  end
170
212
 
171
213
 
214
+ if opts[:generate]
215
+ ## step 3 - generate
216
+ datasets.each do |league_key, seasons|
217
+ seasons.each do |season|
218
+ generate( league: league_key,
219
+ season: season )
220
+ end
221
+ end
222
+ ## for debugging dump page (slug) titles
223
+ pp extra
224
+ end
225
+
226
+
227
+
172
228
  end # def self.main
173
229
  end # module Worldfootball
174
230
 
data/bin/wfbconf ADDED
@@ -0,0 +1,55 @@
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
+ ## download fresh copy?
39
+ ## Worldfootball::Metal.download_schedule( slug )
40
+
41
+ key = args[0] || 'eng.1'
42
+
43
+ league = Worldfootball::LEAGUES[key]
44
+ seasons = league.seasons
45
+ pp seasons
46
+
47
+ puts " #{key} - #{seasons.size} season(s)"
48
+
49
+ puts
50
+ latest = seasons.keys[0]
51
+ puts " latest #{latest}: "
52
+ pp seasons[latest]
53
+
54
+
55
+ 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"