worldfootball 0.1.1 → 0.1.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 +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +4 -12
- data/README.md +36 -1
- data/Rakefile +3 -3
- data/bin/wfb +71 -23
- data/config/leagues.csv +16 -0
- data/lib/worldfootball/build-parse_score.rb +156 -0
- data/lib/worldfootball/build.rb +31 -114
- data/lib/worldfootball/cache.rb +46 -0
- data/lib/worldfootball/config.rb +220 -0
- data/lib/worldfootball/convert.rb +53 -93
- data/lib/worldfootball/download.rb +8 -18
- data/lib/worldfootball/leagues.rb +117 -171
- data/lib/worldfootball/mods.rb +9 -2
- data/lib/worldfootball/page.rb +9 -0
- data/lib/worldfootball/page_schedule.rb +60 -8
- data/lib/worldfootball/version.rb +1 -1
- data/lib/worldfootball.rb +3 -9
- metadata +7 -15
- data/lib/worldfootball/generator.rb +0 -33
- data/lib/worldfootball/leagues/asia.rb +0 -53
- data/lib/worldfootball/leagues/europe--british_isles.rb +0 -64
- data/lib/worldfootball/leagues/europe--central.rb +0 -127
- data/lib/worldfootball/leagues/europe--eastern.rb +0 -82
- data/lib/worldfootball/leagues/europe--northern.rb +0 -57
- data/lib/worldfootball/leagues/europe--southern.rb +0 -86
- data/lib/worldfootball/leagues/europe--western.rb +0 -38
- data/lib/worldfootball/leagues/europe.rb +0 -13
- data/lib/worldfootball/leagues/north_america.rb +0 -44
- data/lib/worldfootball/leagues/pacific.rb +0 -21
- data/lib/worldfootball/leagues/south_america.rb +0 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99623775fef73f0837946ba44625a572bbe5fee3a64aa6aa9a2f6f79702a0d01
|
|
4
|
+
data.tar.gz: 1ed058214bcca9fad1aac5b205e73c101a79a14ef979dbdee37c3a784fe03460
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b2ec98872c3cf9ae5b9f39cd6ac5bcd205ea35a4ea1282a575f8ea9256226f4395c4021b57417e6d77db38b474127b35cd2836aee3d381a8138b318cb588be0
|
|
7
|
+
data.tar.gz: dff2a077af11f10c6c0f1e923e42710b04b198a5c7a7677363a25bfa7e508ec56867d64c2df8f907a51584613b0d86a8f246f6727755fa1dfa1e6c1135962877
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
|
@@ -3,24 +3,16 @@ Manifest.txt
|
|
|
3
3
|
README.md
|
|
4
4
|
Rakefile
|
|
5
5
|
bin/wfb
|
|
6
|
+
config/leagues.csv
|
|
6
7
|
lib/worldfootball.rb
|
|
8
|
+
lib/worldfootball/build-parse_score.rb
|
|
7
9
|
lib/worldfootball/build.rb
|
|
10
|
+
lib/worldfootball/cache.rb
|
|
11
|
+
lib/worldfootball/config.rb
|
|
8
12
|
lib/worldfootball/convert.rb
|
|
9
13
|
lib/worldfootball/convert_reports.rb
|
|
10
14
|
lib/worldfootball/download.rb
|
|
11
|
-
lib/worldfootball/generator.rb
|
|
12
15
|
lib/worldfootball/leagues.rb
|
|
13
|
-
lib/worldfootball/leagues/asia.rb
|
|
14
|
-
lib/worldfootball/leagues/europe--british_isles.rb
|
|
15
|
-
lib/worldfootball/leagues/europe--central.rb
|
|
16
|
-
lib/worldfootball/leagues/europe--eastern.rb
|
|
17
|
-
lib/worldfootball/leagues/europe--northern.rb
|
|
18
|
-
lib/worldfootball/leagues/europe--southern.rb
|
|
19
|
-
lib/worldfootball/leagues/europe--western.rb
|
|
20
|
-
lib/worldfootball/leagues/europe.rb
|
|
21
|
-
lib/worldfootball/leagues/north_america.rb
|
|
22
|
-
lib/worldfootball/leagues/pacific.rb
|
|
23
|
-
lib/worldfootball/leagues/south_america.rb
|
|
24
16
|
lib/worldfootball/mods.rb
|
|
25
17
|
lib/worldfootball/page.rb
|
|
26
18
|
lib/worldfootball/page_report.rb
|
data/README.md
CHANGED
|
@@ -11,7 +11,42 @@
|
|
|
11
11
|
## Usage
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
To
|
|
14
|
+
To get started use the `wfb` command-line tool.
|
|
15
|
+
|
|
16
|
+
List all (pre-configured) leagues:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
$ wfb leagues
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Print the match schedue of a league (season). Let's try the English Premier League:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
$ wfb eng.1 2024/25
|
|
26
|
+
$ wfb eng.1 2024/25 --offline # use cached (offline local) pages
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Or try the DFB Pokal (that is, the German Cup):
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
$ wfb de.cup 2024/25 --offline # use cached (offline local) pages
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
and so on.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
### More
|
|
43
|
+
|
|
44
|
+
Debugging tips. List all cached (offline local) match schedule pages:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
$ wfb cache
|
|
48
|
+
```
|
|
49
|
+
|
|
15
50
|
|
|
16
51
|
|
|
17
52
|
|
data/Rakefile
CHANGED
|
@@ -19,8 +19,8 @@ Hoe.spec 'worldfootball' do
|
|
|
19
19
|
|
|
20
20
|
self.extra_deps = [
|
|
21
21
|
## ['tzinfo'],
|
|
22
|
-
['season-formats'],
|
|
23
|
-
['webget'],
|
|
22
|
+
['season-formats'],
|
|
23
|
+
['webget'],
|
|
24
24
|
['nokogiri'],
|
|
25
25
|
['cocos'], ## later pull in with sportsdb-writers
|
|
26
26
|
]
|
|
@@ -28,7 +28,7 @@ Hoe.spec 'worldfootball' do
|
|
|
28
28
|
self.licenses = ['Public Domain']
|
|
29
29
|
|
|
30
30
|
self.spec_extras = {
|
|
31
|
-
required_ruby_version: '>=
|
|
31
|
+
required_ruby_version: '>= 3.1.0'
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
end
|
data/bin/wfb
CHANGED
|
@@ -9,18 +9,30 @@ require 'worldfootball'
|
|
|
9
9
|
Webcache.root = if File.exist?( '/sports/cache' )
|
|
10
10
|
puts " setting web cache to >/sports/cache<"
|
|
11
11
|
'/sports/cache'
|
|
12
|
-
else
|
|
12
|
+
else
|
|
13
13
|
'./cache'
|
|
14
14
|
end
|
|
15
15
|
|
|
16
|
+
## convert (default) output directory
|
|
17
|
+
Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb')
|
|
18
|
+
puts " setting convert out_dir to >/sports/cache.wfb<"
|
|
19
|
+
'/sports/cache.wfb'
|
|
20
|
+
else
|
|
21
|
+
'.' ## use working dir
|
|
22
|
+
end
|
|
16
23
|
|
|
17
24
|
require 'optparse'
|
|
18
25
|
|
|
19
26
|
|
|
20
27
|
module Worldfootball
|
|
21
|
-
def self.main( args=ARGV )
|
|
28
|
+
def self.main( args=ARGV )
|
|
29
|
+
|
|
30
|
+
opts = {
|
|
31
|
+
cached: false,
|
|
32
|
+
convert: true,
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
|
|
23
|
-
opts = {}
|
|
24
36
|
parser = OptionParser.new do |parser|
|
|
25
37
|
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
|
26
38
|
|
|
@@ -28,12 +40,27 @@ parser = OptionParser.new do |parser|
|
|
|
28
40
|
## check if git has a offline option?? (use same)
|
|
29
41
|
## check for other tools - why? why not?
|
|
30
42
|
|
|
43
|
+
## todo - add a single letter option for offline/cached
|
|
31
44
|
|
|
32
45
|
parser.on( "--cache", "--cached", "--offline",
|
|
33
|
-
"use cached data in
|
|
46
|
+
"use cached data in >#{Webcache.root}<" ) do |cached|
|
|
34
47
|
opts[:cached] = cached
|
|
35
48
|
end
|
|
49
|
+
|
|
50
|
+
parser.on( "--no-convert",
|
|
51
|
+
"turn off conversion to .csv in #{Worldfootball.config.convert.out_dir} - default is (#{!opts[:convert]})" ) do |convert|
|
|
52
|
+
opts[:convert] = !convert
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
parser.on( "--dry",
|
|
56
|
+
"dry run / show league page meta info" ) do |dry|
|
|
57
|
+
opts[:dry] = dry
|
|
58
|
+
end
|
|
36
59
|
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
37
64
|
parser.parse!( args )
|
|
38
65
|
|
|
39
66
|
puts "OPTS:"
|
|
@@ -42,12 +69,19 @@ puts "ARGV:"
|
|
|
42
69
|
p args
|
|
43
70
|
|
|
44
71
|
|
|
72
|
+
### check special (built-in) commands first
|
|
73
|
+
if ['cache'].include?( args[0] )
|
|
74
|
+
Worldfootball.list_pages
|
|
75
|
+
exit 0
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
|
|
45
79
|
if ['league', 'leagues', 'ls'].include?( args[0] || 'leagues' )
|
|
46
80
|
keys = LEAGUES.keys
|
|
47
|
-
|
|
81
|
+
|
|
48
82
|
pp keys
|
|
49
83
|
puts " #{keys.size} league(s)"
|
|
50
|
-
|
|
84
|
+
|
|
51
85
|
# puts
|
|
52
86
|
# puts " pages:"
|
|
53
87
|
# pp Worldfootball::PAGES
|
|
@@ -59,33 +93,42 @@ end
|
|
|
59
93
|
|
|
60
94
|
league_code = args[0].downcase
|
|
61
95
|
|
|
62
|
-
league = find_league( league_code ) ## league info lookup
|
|
63
|
-
|
|
64
|
-
|
|
96
|
+
league = find_league!( league_code ) ## league info lookup
|
|
97
|
+
|
|
98
|
+
if opts[:dry]
|
|
99
|
+
## output more page meta info
|
|
100
|
+
puts "league meta:"
|
|
101
|
+
pp league
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
season = Season( args[1] || '2024/25' )
|
|
106
|
+
|
|
107
|
+
pages = league.pages!( season: season )
|
|
65
108
|
|
|
66
|
-
pages = league.pages( season: season )
|
|
67
109
|
|
|
110
|
+
puts
|
|
68
111
|
pp pages
|
|
69
112
|
puts " #{pages.size} page(s)"
|
|
70
113
|
|
|
71
114
|
|
|
72
|
-
|
|
73
|
-
|
|
115
|
+
if opts[:dry]
|
|
116
|
+
## stop here if dry run
|
|
117
|
+
exit 0
|
|
118
|
+
end
|
|
74
119
|
|
|
75
|
-
|
|
120
|
+
|
|
121
|
+
if opts[:cached]
|
|
76
122
|
# do nothing
|
|
77
123
|
else ## download to cache
|
|
78
|
-
pages.each_with_index do |
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
end
|
|
124
|
+
pages.each_with_index do |(slug,_),i|
|
|
125
|
+
puts "==> #{i+1}/#{pages.size} - #{league_code} @ #{slug}..."
|
|
126
|
+
page = Metal.download_schedule( slug )
|
|
127
|
+
end
|
|
83
128
|
end
|
|
84
129
|
|
|
85
130
|
|
|
86
|
-
pages.each_with_index do |
|
|
87
|
-
slug = page_rec[:slug]
|
|
88
|
-
|
|
131
|
+
pages.each_with_index do |(slug,_),i|
|
|
89
132
|
puts "==> #{i+1}/#{pages.size} - #{league_code} @ #{slug}..."
|
|
90
133
|
page = Page::Schedule.from_cache( slug )
|
|
91
134
|
matches = page.matches
|
|
@@ -94,11 +137,16 @@ pages.each_with_index do |page_rec,i|
|
|
|
94
137
|
end
|
|
95
138
|
|
|
96
139
|
|
|
140
|
+
if opts[:convert]
|
|
141
|
+
## write out (export to) comma-separated values (.csv) datafile
|
|
142
|
+
convert( league: league_code,
|
|
143
|
+
season: season )
|
|
144
|
+
end
|
|
97
145
|
end # def self.main
|
|
98
146
|
end # module Worldfootball
|
|
99
|
-
|
|
147
|
+
|
|
100
148
|
|
|
101
149
|
Worldfootball.main( ARGV )
|
|
102
150
|
|
|
103
|
-
|
|
151
|
+
|
|
104
152
|
puts "bye"
|
data/config/leagues.csv
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
key, slug
|
|
2
|
+
|
|
3
|
+
de.1, bundesliga-2024-2025
|
|
4
|
+
de.2, 2-bundesliga-2024-2025
|
|
5
|
+
de.3, 3-liga-2024-2025
|
|
6
|
+
de.4.bayern, regionalliga-bayern-2024-2025
|
|
7
|
+
de.cup, dfb-pokal-2024-2025
|
|
8
|
+
|
|
9
|
+
at.1, aut-bundesliga-2024-2025
|
|
10
|
+
at.2, aut-2-liga-2024-2025
|
|
11
|
+
at.3.o, aut-regionalliga-ost-2024-2025
|
|
12
|
+
at.cup, aut-oefb-cup-2024-2025
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
module Worldfootball
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def self.parse_score( score_str )
|
|
6
|
+
## add support for
|
|
7
|
+
## 3-0 (0-0, 0-0) Wert.
|
|
8
|
+
## 3-0 (0-0, 0-0) awd.
|
|
9
|
+
|
|
10
|
+
## check for 0:3 Wert. - change Wert. to awd. (awarded)
|
|
11
|
+
## todo/fix - use "hardcoded" Wert\. in regex - why? why not?
|
|
12
|
+
## score_str = score_str.sub( /Wert\./i, 'awd.' )
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
comments = String.new ## check - rename to/use status or such - why? why not?
|
|
16
|
+
|
|
17
|
+
## split score
|
|
18
|
+
ft = ''
|
|
19
|
+
ht = ''
|
|
20
|
+
et = ''
|
|
21
|
+
pen = ''
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if score_str == '---' ## in the future (no score yet) - was -:-
|
|
25
|
+
ft = ''
|
|
26
|
+
ht = ''
|
|
27
|
+
elsif score_str == 'n.gesp.' || ## cancelled (british) / canceled (us)
|
|
28
|
+
score_str == 'ausg.' || ## todo/check: change to some other status ????
|
|
29
|
+
score_str == 'annull.' ## todo/check: change to some other status (see ie 2012) ????
|
|
30
|
+
ft = '(*)'
|
|
31
|
+
ht = ''
|
|
32
|
+
comments = 'cancelled'
|
|
33
|
+
elsif score_str == 'abgebr.' ## abandoned -- waiting for replay?
|
|
34
|
+
ft = '(*)'
|
|
35
|
+
ht = ''
|
|
36
|
+
comments = 'abandoned'
|
|
37
|
+
elsif score_str == 'verl.' ## postponed
|
|
38
|
+
ft = ''
|
|
39
|
+
ht = ''
|
|
40
|
+
comments = 'postponed'
|
|
41
|
+
# 5-4 (0-0, 1-1, 2-2) i.E.
|
|
42
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
43
|
+
[ ]*
|
|
44
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
45
|
+
[ ]*,[ ]*
|
|
46
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
47
|
+
[ ]*,[ ]*
|
|
48
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)\)
|
|
49
|
+
[ ]*
|
|
50
|
+
i\.E\.
|
|
51
|
+
/x
|
|
52
|
+
pen = "#{$1}-#{$2}"
|
|
53
|
+
ht = "#{$3}-#{$4}"
|
|
54
|
+
ft = "#{$5}-#{$6}"
|
|
55
|
+
et = "#{$7}-#{$8}"
|
|
56
|
+
# 3-2 (0-0, 1-1) i.E. - note: no extra time!!! only ht,ft!!!
|
|
57
|
+
# "popular" in southamerica & mexico
|
|
58
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
59
|
+
[ ]*
|
|
60
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
61
|
+
[ ]*,[ ]*
|
|
62
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)\)
|
|
63
|
+
[ ]*
|
|
64
|
+
i\.E\.
|
|
65
|
+
/x
|
|
66
|
+
pen = "#{$1}-#{$2}"
|
|
67
|
+
ht = "#{$3}-#{$4}"
|
|
68
|
+
ft = "#{$5}-#{$6}"
|
|
69
|
+
et = ''
|
|
70
|
+
# 2-1 (1-0, 1-1) n.V
|
|
71
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
72
|
+
[ ]*
|
|
73
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
74
|
+
[ ]*,[ ]*
|
|
75
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
76
|
+
\)
|
|
77
|
+
[ ]*
|
|
78
|
+
n\.V\.
|
|
79
|
+
/x
|
|
80
|
+
et = "#{$1}-#{$2}"
|
|
81
|
+
ht = "#{$3}-#{$4}"
|
|
82
|
+
ft = "#{$5}-#{$6}"
|
|
83
|
+
### auto-patch fix drop last score
|
|
84
|
+
## 1-3 (0-1, 1-1, 0-2) n.V. => 1-3 (0-1, 1-1) n.V.
|
|
85
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
86
|
+
[ ]*
|
|
87
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
88
|
+
[ ]*,[ ]*
|
|
89
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
90
|
+
[ ]*,[ ]*
|
|
91
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
92
|
+
\)
|
|
93
|
+
[ ]*
|
|
94
|
+
n\.V\.
|
|
95
|
+
/x
|
|
96
|
+
et = "#{$1}-#{$2}"
|
|
97
|
+
ht = "#{$3}-#{$4}"
|
|
98
|
+
ft = "#{$5}-#{$6}"
|
|
99
|
+
|
|
100
|
+
puts "!! WARN - auto-fix/patch score - >#{score_str}<"
|
|
101
|
+
### todo/fix - log auto-patch/fix - for double checking!!!!!
|
|
102
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
103
|
+
[ ]*
|
|
104
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
105
|
+
\)
|
|
106
|
+
/x
|
|
107
|
+
ft = "#{$1}-#{$2}"
|
|
108
|
+
ht = "#{$3}-#{$4}"
|
|
109
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
110
|
+
[ ]*
|
|
111
|
+
Wert\. # ([a-z.]+)
|
|
112
|
+
/x ### assume awd. (awarded) always - why? why not?
|
|
113
|
+
ft = "#{$1}-#{$2} (*)"
|
|
114
|
+
ht = ''
|
|
115
|
+
comments = 'awd.' # awarded - $3
|
|
116
|
+
## auto-fix/patch
|
|
117
|
+
## drop last scores (only use ft)
|
|
118
|
+
## 3-0 (0-0, 0-0) awd.
|
|
119
|
+
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
120
|
+
[ ]*
|
|
121
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
122
|
+
[ ]*,[ ]*
|
|
123
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
124
|
+
\)
|
|
125
|
+
[ ]*
|
|
126
|
+
Wert\. # ([a-z.]+)
|
|
127
|
+
/x ### assume awd. (awarded) always - why? why not?
|
|
128
|
+
ft = "#{$1}-#{$2} (*)"
|
|
129
|
+
ht = ''
|
|
130
|
+
comments = 'awd.' # awarded - $7
|
|
131
|
+
## (auto) log case for double checking - why? why not?
|
|
132
|
+
elsif score_str =~ /^([0-9]+)-([0-9]+)$/
|
|
133
|
+
ft = "#{$1}-#{$2}" ## e.g. see luxemburg and others
|
|
134
|
+
ht = ''
|
|
135
|
+
## auto-fix/patch
|
|
136
|
+
# 3-3 (0-3, 3-3) => 3-3 (0-3) - drop last score
|
|
137
|
+
elsif score_str =~ /^([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
138
|
+
[ ]*
|
|
139
|
+
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
140
|
+
[ ]*,[ ]*
|
|
141
|
+
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
142
|
+
\)$
|
|
143
|
+
/x
|
|
144
|
+
ft = "#{$1}-#{$2}"
|
|
145
|
+
ht = "#{$3}-#{$4}"
|
|
146
|
+
|
|
147
|
+
puts "!! WARN - auto-fix/patch score - >#{score_str}<"
|
|
148
|
+
### todo/fix - log auto-patch/fix - for double checking!!!!!
|
|
149
|
+
else
|
|
150
|
+
puts "!! ERROR - unsupported score format >#{score_str}< - sorry; maybe add a score error fix/patch"
|
|
151
|
+
exit 1
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
[ht, ft, et, pen, comments]
|
|
155
|
+
end
|
|
156
|
+
end # module Worldfootball
|
data/lib/worldfootball/build.rb
CHANGED
|
@@ -7,6 +7,9 @@ ROUND_TO_EN = {
|
|
|
7
7
|
'2. Runde' => 'Round 2',
|
|
8
8
|
'3. Runde' => 'Round 3',
|
|
9
9
|
'4. Runde' => 'Round 4',
|
|
10
|
+
'5. Runde' => 'Round 5',
|
|
11
|
+
'6. Runde' => 'Round 6',
|
|
12
|
+
'7. Runde' => 'Round 7',
|
|
10
13
|
'Achtelfinale' => 'Round of 16',
|
|
11
14
|
'Viertelfinale' => 'Quarterfinals',
|
|
12
15
|
'Halbfinale' => 'Semifinals',
|
|
@@ -20,9 +23,10 @@ ROUND_TO_EN = {
|
|
|
20
23
|
def self.build( rows, season:, league:, stage: '' ) ## rename to fixup or such - why? why not?
|
|
21
24
|
season = Season( season ) ## cast (ensure) season class (NOT string, integer, etc.)
|
|
22
25
|
|
|
23
|
-
|
|
26
|
+
## note: do NOT pass in league struct! pass in key (string)
|
|
27
|
+
raise ArgumentError, "league key as string expected" unless league.is_a?(String)
|
|
24
28
|
|
|
25
|
-
print " #{rows.size}
|
|
29
|
+
print " #{rows.size} row(s) - Worldfootball.build #{league} #{season}"
|
|
26
30
|
print " - #{stage}" unless stage.empty?
|
|
27
31
|
print "\n"
|
|
28
32
|
|
|
@@ -47,44 +51,49 @@ def self.build( rows, season:, league:, stage: '' ) ## rename to fixup or such
|
|
|
47
51
|
print '[%03d] ' % (i+1)
|
|
48
52
|
print row[:round]
|
|
49
53
|
|
|
50
|
-
if m = row[:round].match(
|
|
54
|
+
if (m = row[:round].match( /^(?<num>[0-9]+)\. Spieltag$/ ))
|
|
51
55
|
## todo/check: always use a string even if number (as a string eg. '1' etc.)
|
|
52
|
-
round = m[
|
|
56
|
+
round = m[:num] ## note: keep as string (NOT number)
|
|
53
57
|
print " => #{round}"
|
|
54
58
|
else
|
|
55
|
-
puts "!! ERROR: cannot find matchday number"
|
|
59
|
+
puts "!! ERROR: cannot find matchday number in >#{row[:round]}<:"
|
|
60
|
+
pp row
|
|
56
61
|
exit 1
|
|
57
62
|
end
|
|
58
63
|
print "\n"
|
|
59
|
-
|
|
64
|
+
|
|
65
|
+
## note - must start line e.g.
|
|
66
|
+
## do NOT match => Qual. 1. Runde (1. Runde)!!!
|
|
67
|
+
elsif row[:round] =~ /^(
|
|
68
|
+
[1-9]\.[ ]Runde|
|
|
60
69
|
Achtelfinale|
|
|
61
70
|
Viertelfinale|
|
|
62
71
|
Halbfinale|
|
|
63
72
|
Finale
|
|
64
|
-
|
|
73
|
+
)$
|
|
74
|
+
/x
|
|
65
75
|
puts
|
|
66
76
|
print '[%03d] ' % (i+1)
|
|
67
77
|
print row[:round]
|
|
68
78
|
|
|
79
|
+
round = ROUND_TO_EN[ row[:round] ]
|
|
80
|
+
print " => #{round}"
|
|
81
|
+
print "\n"
|
|
69
82
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
else
|
|
75
|
-
round = ROUND_TO_EN[ row[:round] ]
|
|
76
|
-
if round.nil?
|
|
77
|
-
puts "!! ERROR: no mapping for round to english (en) found >#{row[:round]}<:"
|
|
78
|
-
pp row
|
|
79
|
-
exit 1
|
|
80
|
-
end
|
|
81
|
-
print " => #{round}"
|
|
83
|
+
if round.nil?
|
|
84
|
+
puts "!! ERROR: no mapping for round to english (en) found >#{row[:round]}<:"
|
|
85
|
+
pp row
|
|
86
|
+
exit 1
|
|
82
87
|
end
|
|
83
|
-
print "\n"
|
|
84
88
|
else
|
|
85
|
-
puts
|
|
89
|
+
puts
|
|
90
|
+
print '[%03d] ' % (i+1)
|
|
91
|
+
print row[:round]
|
|
92
|
+
print "\n"
|
|
93
|
+
|
|
94
|
+
puts "!! WARN: unknown round >#{row[:round]}< for league >#{league}<:"
|
|
86
95
|
pp row
|
|
87
|
-
|
|
96
|
+
round = row[:round]
|
|
88
97
|
end
|
|
89
98
|
|
|
90
99
|
|
|
@@ -123,8 +132,6 @@ def self.build( rows, season:, league:, stage: '' ) ## rename to fixup or such
|
|
|
123
132
|
print "\n"
|
|
124
133
|
|
|
125
134
|
|
|
126
|
-
## check for 0:3 Wert. - change Wert. to awd. (awarded)
|
|
127
|
-
score_str = score_str.sub( /Wert\./i, 'awd.' )
|
|
128
135
|
|
|
129
136
|
## clean team name (e.g. remove (old))
|
|
130
137
|
## and asciify (e.g. ’ to ' )
|
|
@@ -135,12 +142,9 @@ def self.build( rows, season:, league:, stage: '' ) ## rename to fixup or such
|
|
|
135
142
|
team2_str = mods[ team2_str ] if mods[ team2_str ]
|
|
136
143
|
|
|
137
144
|
|
|
138
|
-
|
|
139
|
-
|
|
140
145
|
ht, ft, et, pen, comments = parse_score( score_str )
|
|
141
146
|
|
|
142
147
|
|
|
143
|
-
|
|
144
148
|
recs << [stage,
|
|
145
149
|
round,
|
|
146
150
|
date.strftime( '%Y-%m-%d' ),
|
|
@@ -155,91 +159,4 @@ def self.build( rows, season:, league:, stage: '' ) ## rename to fixup or such
|
|
|
155
159
|
end # each row
|
|
156
160
|
recs
|
|
157
161
|
end # build
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
def self.parse_score( score_str )
|
|
162
|
-
comments = String.new( '' ) ## check - rename to/use status or such - why? why not?
|
|
163
|
-
|
|
164
|
-
## split score
|
|
165
|
-
ft = ''
|
|
166
|
-
ht = ''
|
|
167
|
-
et = ''
|
|
168
|
-
pen = ''
|
|
169
|
-
if score_str == '---' ## in the future (no score yet) - was -:-
|
|
170
|
-
ft = ''
|
|
171
|
-
ht = ''
|
|
172
|
-
elsif score_str == 'n.gesp.' || ## cancelled (british) / canceled (us)
|
|
173
|
-
score_str == 'ausg.' || ## todo/check: change to some other status ????
|
|
174
|
-
score_str == 'annull.' ## todo/check: change to some other status (see ie 2012) ????
|
|
175
|
-
ft = '(*)'
|
|
176
|
-
ht = ''
|
|
177
|
-
comments = 'cancelled'
|
|
178
|
-
elsif score_str == 'abgebr.' ## abandoned -- waiting for replay?
|
|
179
|
-
ft = '(*)'
|
|
180
|
-
ht = ''
|
|
181
|
-
comments = 'abandoned'
|
|
182
|
-
elsif score_str == 'verl.' ## postponed
|
|
183
|
-
ft = ''
|
|
184
|
-
ht = ''
|
|
185
|
-
comments = 'postponed'
|
|
186
|
-
# 5-4 (0-0, 1-1, 2-2) i.E.
|
|
187
|
-
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
188
|
-
[ ]*
|
|
189
|
-
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
190
|
-
[ ]*,[ ]*
|
|
191
|
-
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
192
|
-
[ ]*,[ ]*
|
|
193
|
-
([0-9]+) [ ]*-[ ]* ([0-9]+)\)
|
|
194
|
-
[ ]*
|
|
195
|
-
i\.E\.
|
|
196
|
-
/x
|
|
197
|
-
pen = "#{$1}-#{$2}"
|
|
198
|
-
ht = "#{$3}-#{$4}"
|
|
199
|
-
ft = "#{$5}-#{$6}"
|
|
200
|
-
et = "#{$7}-#{$8}"
|
|
201
|
-
# 2-1 (1-0, 1-1) n.V
|
|
202
|
-
elsif score_str =~ /([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
203
|
-
[ ]*
|
|
204
|
-
\(([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
205
|
-
[ ]*,[ ]*
|
|
206
|
-
([0-9]+) [ ]*-[ ]* ([0-9]+)
|
|
207
|
-
\)
|
|
208
|
-
[ ]*
|
|
209
|
-
n\.V\.
|
|
210
|
-
/x
|
|
211
|
-
et = "#{$1}-#{$2}"
|
|
212
|
-
ht = "#{$3}-#{$4}"
|
|
213
|
-
ft = "#{$5}-#{$6}"
|
|
214
|
-
elsif score_str =~ /([0-9]+)
|
|
215
|
-
[ ]*-[ ]*
|
|
216
|
-
([0-9]+)
|
|
217
|
-
[ ]*
|
|
218
|
-
\(([0-9]+)
|
|
219
|
-
[ ]*-[ ]*
|
|
220
|
-
([0-9]+)
|
|
221
|
-
\)
|
|
222
|
-
/x
|
|
223
|
-
ft = "#{$1}-#{$2}"
|
|
224
|
-
ht = "#{$3}-#{$4}"
|
|
225
|
-
elsif score_str =~ /([0-9]+)
|
|
226
|
-
[ ]*-[ ]*
|
|
227
|
-
([0-9]+)
|
|
228
|
-
[ ]*
|
|
229
|
-
([a-z.]+)
|
|
230
|
-
/x
|
|
231
|
-
ft = "#{$1}-#{$2} (*)"
|
|
232
|
-
ht = ''
|
|
233
|
-
comments = $3
|
|
234
|
-
elsif score_str =~ /^([0-9]+)-([0-9]+)$/
|
|
235
|
-
ft = "#{$1}-#{$2}" ## e.g. see luxemburg and others
|
|
236
|
-
ht = ''
|
|
237
|
-
else
|
|
238
|
-
puts "!! ERROR - unsupported score format >#{score_str}< - sorry; maybe add a score error fix/patch"
|
|
239
|
-
exit 1
|
|
240
|
-
end
|
|
241
|
-
|
|
242
|
-
[ht, ft, et, pen, comments]
|
|
243
|
-
end
|
|
244
|
-
|
|
245
162
|
end # module Worldfootball
|