rsssf 0.1.0 → 0.3.0
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 +5 -5
- data/{HISTORY.md → CHANGELOG.md} +4 -0
- data/Manifest.txt +41 -7
- data/README.md +93 -71
- data/Rakefile +8 -7
- data/config/groups_en.txt +44 -0
- data/config/rounds_en.txt +283 -0
- data/config/rounds_es.txt +20 -0
- data/config/rounds_misc.txt +7 -0
- data/lib/_cocos_.rb +158 -0
- data/lib/rsssf/convert/convert.rb +71 -0
- data/lib/rsssf/convert/errata.rb +103 -0
- data/lib/rsssf/convert/html_entities.rb +150 -0
- data/lib/rsssf/convert/html_to_txt/beautify_anchors.rb +96 -0
- data/lib/rsssf/convert/html_to_txt/make_heading.rb +70 -0
- data/lib/rsssf/convert/html_to_txt/remove_emails.rb +43 -0
- data/lib/rsssf/convert/html_to_txt/replace_a_href.rb +85 -0
- data/lib/rsssf/convert/html_to_txt/replace_a_name.rb +87 -0
- data/lib/rsssf/convert/html_to_txt/replace_heading.rb +76 -0
- data/lib/rsssf/convert/html_to_txt/replace_hr.rb +25 -0
- data/lib/rsssf/convert/html_to_txt.rb +247 -0
- data/lib/rsssf/download.rb +20 -0
- data/lib/rsssf/fmtfix/dates.rb +541 -0
- data/lib/rsssf/fmtfix/dates_helpers.rb +63 -0
- data/lib/rsssf/fmtfix/errata.rb +44 -0
- data/lib/rsssf/fmtfix/fmtfix-base.rb +68 -0
- data/lib/rsssf/fmtfix/fmtfix.rb +101 -0
- data/lib/rsssf/fmtfix/goals.rb +173 -0
- data/lib/rsssf/fmtfix/headers.rb +326 -0
- data/lib/rsssf/fmtfix/outline.rb +228 -0
- data/lib/rsssf/fmtfix/patch_headings.rb +141 -0
- data/lib/rsssf/fmtfix/rounds.rb +74 -0
- data/lib/rsssf/fmtfix/score.rb +92 -0
- data/lib/rsssf/fmtfix/tables.rb +316 -0
- data/lib/rsssf/fmtfix/topscorers.rb +50 -0
- data/lib/rsssf/page-find_schedule.rb +127 -0
- data/lib/rsssf/page-meta.rb +68 -0
- data/lib/rsssf/page.rb +125 -238
- data/lib/rsssf/parse_schedules.rb +34 -0
- data/lib/rsssf/prepare/convert-links.rb +77 -0
- data/lib/rsssf/prepare/convert-meta.rb +111 -0
- data/lib/rsssf/prepare/convert-navlines.rb +154 -0
- data/lib/rsssf/prepare/convert-postproc.rb +141 -0
- data/lib/rsssf/prepare/convert.rb +100 -0
- data/lib/rsssf/prepare/download.rb +40 -0
- data/lib/rsssf/project.rb +154 -0
- data/lib/rsssf/reports/page.rb +66 -23
- data/lib/rsssf/reports/schedule.rb +89 -40
- data/lib/rsssf/schedule.rb +4 -14
- data/lib/rsssf/utils.rb +37 -45
- data/lib/rsssf/version.rb +7 -6
- data/lib/rsssf.rb +82 -19
- metadata +68 -26
- data/.gemtest +0 -0
- data/lib/rsssf/fetch.rb +0 -80
- data/lib/rsssf/html2txt.rb +0 -157
- data/lib/rsssf/patch.rb +0 -28
- data/lib/rsssf/repo.rb +0 -220
- data/test/helper.rb +0 -12
- data/test/test_utils.rb +0 -83
data/lib/rsssf/fetch.rb
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Rsssf
|
|
4
|
-
|
|
5
|
-
class PageFetcher
|
|
6
|
-
|
|
7
|
-
include Filters # e.g. html2text, sanitize etc.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
def initialize
|
|
11
|
-
@worker = Fetcher::Worker.new
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
def fetch( src_url )
|
|
15
|
-
|
|
16
|
-
## note: assume plain 7-bit ascii for now
|
|
17
|
-
## -- assume rsssf uses ISO_8859_15 (updated version of ISO_8859_1) -- does NOT use utf-8 character encoding!!!
|
|
18
|
-
html = @worker.read( src_url )
|
|
19
|
-
|
|
20
|
-
### todo/fix: first check if html is all ascii-7bit e.g.
|
|
21
|
-
## includes only chars from 64 to 127!!!
|
|
22
|
-
|
|
23
|
-
## normalize newlines
|
|
24
|
-
## remove \r (form feed) used by Windows; just use \n (new line)
|
|
25
|
-
html = html.gsub( "\r", '' )
|
|
26
|
-
|
|
27
|
-
## note:
|
|
28
|
-
## assume (default) to ISO 3166-15 (an updated version of ISO 3166-1) for now
|
|
29
|
-
##
|
|
30
|
-
## other possible alternatives - try:
|
|
31
|
-
## - Windows CP 1562 or
|
|
32
|
-
## - ISO 3166-2 (for eastern european languages )
|
|
33
|
-
##
|
|
34
|
-
## note: german umlaut use the same code (int)
|
|
35
|
-
## in ISO 3166-1/15 and 2 and Windows CP1562 (other chars ARE different!!!)
|
|
36
|
-
|
|
37
|
-
html = html.force_encoding( Encoding::ISO_8859_15 )
|
|
38
|
-
html = html.encode( Encoding::UTF_8 ) # try conversion to utf-8
|
|
39
|
-
|
|
40
|
-
## check for html entities
|
|
41
|
-
html = html.gsub( "ä", 'ä' )
|
|
42
|
-
html = html.gsub( "ö", 'ö' )
|
|
43
|
-
html = html.gsub( "ü", 'ü' )
|
|
44
|
-
html = html.gsub( "Ä", 'Ä' )
|
|
45
|
-
html = html.gsub( "Ö", 'Ö' )
|
|
46
|
-
html = html.gsub( "Ü", 'Ü' )
|
|
47
|
-
html = html.gsub( "ß", 'ß' )
|
|
48
|
-
|
|
49
|
-
html = html.gsub( "&oulm;", 'ö' ) ## support typo in entity (ö)
|
|
50
|
-
html = html.gsub( "&slig;", "ß" ) ## support typo in entity (ß)
|
|
51
|
-
|
|
52
|
-
html = html.gsub( "É", 'É' )
|
|
53
|
-
html = html.gsub( "ø", 'ø' )
|
|
54
|
-
|
|
55
|
-
## check for more entities
|
|
56
|
-
html = html.gsub( /&[^;]+;/) do |match|
|
|
57
|
-
puts "*** found unencoded html entity #{match}"
|
|
58
|
-
match ## pass through as is (1:1)
|
|
59
|
-
end
|
|
60
|
-
## todo/fix: add more entities
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
txt = html_to_txt( html )
|
|
64
|
-
|
|
65
|
-
header = <<EOS
|
|
66
|
-
<!--
|
|
67
|
-
source: #{src_url}
|
|
68
|
-
-->
|
|
69
|
-
|
|
70
|
-
EOS
|
|
71
|
-
|
|
72
|
-
header+txt ## return txt w/ header
|
|
73
|
-
end ## method fetch
|
|
74
|
-
|
|
75
|
-
end ## class PageFetcher
|
|
76
|
-
end ## module Rsssf
|
|
77
|
-
|
|
78
|
-
## add (shortcut) alias
|
|
79
|
-
RsssfPageFetcher = Rsssf::PageFetcher
|
|
80
|
-
|
data/lib/rsssf/html2txt.rb
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Rsssf
|
|
4
|
-
module Filters
|
|
5
|
-
|
|
6
|
-
def html_to_txt( html )
|
|
7
|
-
|
|
8
|
-
###
|
|
9
|
-
# todo: check if any tags (still) present??
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
## cut off everything before body
|
|
13
|
-
html = html.sub( /.+?<BODY>\s*/im, '' )
|
|
14
|
-
|
|
15
|
-
## cut off everything after body (closing)
|
|
16
|
-
html = html.sub( /<\/BODY>.*/im, '' )
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
## remove cite
|
|
20
|
-
html = html.gsub( /<CITE>([^<]+)<\/CITE>/im ) do |_|
|
|
21
|
-
puts " remove cite >#{$1}<"
|
|
22
|
-
"#{$1}"
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
html = html.gsub( /\s*<HR>\s*/im ) do |match|
|
|
26
|
-
match = match.gsub( "\n", '$$' ) ## make newlines visible for debugging
|
|
27
|
-
puts " replace horizontal rule (hr) - >#{match}<"
|
|
28
|
-
"\n=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n" ## check what hr to use use - . - . - or =-=-=-= or somehting distinct?
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
## replace break (br)
|
|
32
|
-
## note: do NOT use m/multiline for now - why? why not??
|
|
33
|
-
html = html.gsub( /<BR>\s*/i ) do |match| ## note: include (swallow) "extra" newline
|
|
34
|
-
match = match.gsub( "\n", '$$' ) ## make newlines visible for debugging
|
|
35
|
-
puts " replace break (br) - >#{match}<"
|
|
36
|
-
"\n"
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
## remove anchors (a name)
|
|
40
|
-
html = html.gsub( /<A NAME[^>]*>(.+?)<\/A>/im ) do |match| ## note: use .+? non-greedy match
|
|
41
|
-
title = $1.to_s ## note: "save" caputure first; gets replaced by gsub (next regex call)
|
|
42
|
-
match = match.gsub( "\n", '$$' ) ## make newlines visible for debugging
|
|
43
|
-
puts " replace anchor (a) name >#{title}< - >#{match}<"
|
|
44
|
-
"#{title}"
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
## remove anchors (a href)
|
|
48
|
-
# note: heading 4 includes anchor (thus, let anchors go first)
|
|
49
|
-
# note: <a \newline href is used for authors email - thus incl. support for newline as space
|
|
50
|
-
html = html.gsub( /<A\s+HREF[^>]*>(.+?)<\/A>/im ) do |_| ## note: use .+? non-greedy match
|
|
51
|
-
puts " replace anchor (a) href >#{$1}<"
|
|
52
|
-
"‹#{$1}›"
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
## replace paragrah (p)
|
|
56
|
-
html = html.gsub( /\s*<P>\s*/im ) do |match| ## note: include (swallow) "extra" newline
|
|
57
|
-
match = match.gsub( "\n", '$$' ) ## make newlines visible for debugging
|
|
58
|
-
puts " replace paragraph (p) - >#{match}<"
|
|
59
|
-
"\n\n"
|
|
60
|
-
end
|
|
61
|
-
html = html.gsub( /<\/P>/i, '' ) ## replace paragraph (p) closing w/ nothing for now
|
|
62
|
-
|
|
63
|
-
## remove i
|
|
64
|
-
html = html.gsub( /<I>([^<]+)<\/I>/im ) do |_|
|
|
65
|
-
puts " remove italic (i) >#{$1}<"
|
|
66
|
-
"#{$1}"
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
## heading 2
|
|
71
|
-
html = html.gsub( /\s*<H2>([^<]+)<\/H2>\s*/im ) do |_|
|
|
72
|
-
puts " replace heading 2 (h2) >#{$1}<"
|
|
73
|
-
"\n\n## #{$1}\n\n" ## note: make sure to always add two newlines
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
## heading 4
|
|
77
|
-
html = html.gsub( /\s*<H4>([^<]+)<\/H4>\s*/im ) do |_|
|
|
78
|
-
puts " replace heading 4 (h4) >#{$1}<"
|
|
79
|
-
"\n\n#### #{$1}\n\n" ## note: make sure to always add two newlines
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
## remove b - note: might include anchors (thus, call after anchors)
|
|
84
|
-
html = html.gsub( /<B>([^<]+)<\/B>/im ) do |_|
|
|
85
|
-
puts " remove bold (b) >#{$1}<"
|
|
86
|
-
"**#{$1}**"
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
## replace preformatted (pre)
|
|
90
|
-
html = html.gsub( /<PRE>|<\/PRE>/i ) do |_|
|
|
91
|
-
puts " replace preformatted (pre)"
|
|
92
|
-
'' # replace w/ nothing for now (keep surrounding newlines)
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
=begin
|
|
96
|
-
puts
|
|
97
|
-
puts
|
|
98
|
-
puts "html:"
|
|
99
|
-
puts html[0..2000]
|
|
100
|
-
puts "-- snip --"
|
|
101
|
-
puts html[-1000..-1] ## print last hundred chars
|
|
102
|
-
=end
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
## cleanup whitespaces
|
|
106
|
-
## todo/fix: convert newline in space first
|
|
107
|
-
## and than collapse spaces etc.!!!
|
|
108
|
-
txt = ''
|
|
109
|
-
html.each_line do |line|
|
|
110
|
-
line = line.gsub( "\t", ' ' ) # replace all tabs w/ two spaces for nwo
|
|
111
|
-
line = line.rstrip # remove trailing whitespace (incl. newline/formfeed)
|
|
112
|
-
|
|
113
|
-
txt << line
|
|
114
|
-
txt << "\n"
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
### remove emails etc.
|
|
118
|
-
txt = sanitize( txt )
|
|
119
|
-
|
|
120
|
-
txt
|
|
121
|
-
end # method html_to_text
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
def sanitize( txt )
|
|
126
|
-
### remove emails for (spam/privacy) protection
|
|
127
|
-
## e.g. (selamm@example.es)
|
|
128
|
-
## (buuu@mscs.dal.ca)
|
|
129
|
-
## (kaxx@rsssf.com)
|
|
130
|
-
## (Manu_Maya@yakoo.co)
|
|
131
|
-
|
|
132
|
-
## note add support for optional ‹› enclosure (used by html2txt converted a href :mailto links)
|
|
133
|
-
## e.g. (‹selamm@example.es›)
|
|
134
|
-
|
|
135
|
-
email_pattern = "\\(‹?[a-z][a-z0-9_]+@[a-z]+(\\.[a-z]+)+›?\\)" ## note: just a string; needs to escape \\ twice!!!
|
|
136
|
-
|
|
137
|
-
## check for "free-standing e.g. on its own line" emails only for now
|
|
138
|
-
txt = txt.gsub( /\n#{email_pattern}\n/i ) do |match|
|
|
139
|
-
puts "removing (free-standing) email >#{match}<"
|
|
140
|
-
"\n" # return empty line
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
txt = txt.gsub( /#{email_pattern}/i ) do |match|
|
|
144
|
-
puts "remove email >#{match}<"
|
|
145
|
-
''
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
txt
|
|
149
|
-
end # method sanitize
|
|
150
|
-
|
|
151
|
-
end # module Filters
|
|
152
|
-
end # module Rsssf
|
|
153
|
-
|
|
154
|
-
## add (shortcut) alias
|
|
155
|
-
RsssfFilters = Rsssf::Filters
|
|
156
|
-
|
|
157
|
-
|
data/lib/rsssf/patch.rb
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Rsssf
|
|
4
|
-
|
|
5
|
-
class Patcher
|
|
6
|
-
|
|
7
|
-
## e.g. 2008/09
|
|
8
|
-
## note: also support 1999/2000
|
|
9
|
-
SEASON = '\d{4}\/(\d{2}|\d{4})' ## note: use single quotes - quotes do NOT get escaped (e.g. '\d' => "\\d")
|
|
10
|
-
|
|
11
|
-
def patch_heading( txt, rxs, title )
|
|
12
|
-
rxs.each do |rx|
|
|
13
|
-
txt = txt.sub( rx ) do |match|
|
|
14
|
-
match = match.gsub( "\n", '$$') ## change newlines to $$ for single-line outputs/dumps
|
|
15
|
-
puts " found heading >#{match}<"
|
|
16
|
-
"\n\n#### #{title}\n\n"
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
txt
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
end # class Patcher
|
|
24
|
-
end ## module Rsssf
|
|
25
|
-
|
|
26
|
-
## add (shortcut) alias
|
|
27
|
-
RsssfPatcher = Rsssf::Patcher
|
|
28
|
-
|
data/lib/rsssf/repo.rb
DELETED
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
module Rsssf
|
|
4
|
-
|
|
5
|
-
## used by Repo#make_schedules
|
|
6
|
-
ScheduleConfig = Struct.new(
|
|
7
|
-
:name,
|
|
8
|
-
:opts_for_year, ## hash or proc ->(year){ Hash[...] }
|
|
9
|
-
:dir_for_year, ## proc ->(year){ 'path_here'} ## rename to path_for_year - why, why not??
|
|
10
|
-
:includes ## array of years to include e.g. [2011,2012] etc.
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
ScheduleStat = Struct.new(
|
|
15
|
-
:path, ## e.g. 2012-13 or archive/1980s/1984-85
|
|
16
|
-
:filename, ## e.g. 1-bundesliga.txt -- note: w/o path
|
|
17
|
-
:year, ## e.g. 2013 -- note: numeric (integer)
|
|
18
|
-
:season, ## e.g. 2012-13 -- note: is a string
|
|
19
|
-
:rounds ## e.g. 36 -- note: numeric (integer)
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class Repo
|
|
24
|
-
|
|
25
|
-
include Filters ## e.g. sanitize, etc.
|
|
26
|
-
include Utils ## e.g. year_from_file, etc.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def initialize( path, opts ) ## pass in title etc.
|
|
30
|
-
@repo_path = path
|
|
31
|
-
@opts = opts
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
def fetch_pages
|
|
36
|
-
puts "fetch_pages:"
|
|
37
|
-
cfg = YAML.load_file( "#{@repo_path}/tables/config.yml")
|
|
38
|
-
pp cfg
|
|
39
|
-
|
|
40
|
-
dl_base = 'http://rsssf.com'
|
|
41
|
-
|
|
42
|
-
cfg.each do |k,v|
|
|
43
|
-
## season = k # as string e.g. 2011-12 or 2011 etc.
|
|
44
|
-
path = v # as string e.g. tablesd/duit2011.html
|
|
45
|
-
|
|
46
|
-
## note: assumes extension is .html
|
|
47
|
-
# e.g. tablesd/duit2011.html => duit2011
|
|
48
|
-
basename = File.basename( path, '.html' )
|
|
49
|
-
|
|
50
|
-
src_url = "#{dl_base}/#{path}"
|
|
51
|
-
dest_path = "#{@repo_path}/tables/#{basename}.txt"
|
|
52
|
-
|
|
53
|
-
page = Page.from_url( src_url )
|
|
54
|
-
page.save( dest_path )
|
|
55
|
-
end # each year
|
|
56
|
-
end # method fetch_pages
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def make_pages_summary
|
|
60
|
-
stats = []
|
|
61
|
-
|
|
62
|
-
files = Dir[ "#{@repo_path}/tables/*.txt" ]
|
|
63
|
-
files.each do |file|
|
|
64
|
-
page = Page.from_file( file )
|
|
65
|
-
stats << page.build_stat
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
### save report as README.md in tables/ folder in repo
|
|
69
|
-
report = PageReport.new( stats, @opts ) ## pass in title etc.
|
|
70
|
-
report.save( "#{@repo_path}/tables/README.md" )
|
|
71
|
-
end # method make_pages_summary
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def make_schedules_summary( stats ) ## note: requires stats to be passed in for now
|
|
75
|
-
report = ScheduleReport.new( stats, @opts ) ## pass in title etc.
|
|
76
|
-
report.save( "#{@repo_path}/README.md" )
|
|
77
|
-
end # method make_schedules_summary
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def patch_pages( patcher )
|
|
82
|
-
## lets you run/use custom (repo/country-specific patches e.g. for adding/patching headings etc.)
|
|
83
|
-
patch_dir( "#{@repo_path}/tables" ) do |txt, name, year|
|
|
84
|
-
puts "patching #{year} (#{name}) (#{@repo_path})..."
|
|
85
|
-
patcher.patch( txt, name, year ) ## note: must be last (that is, must return (patcher) t(e)xt)
|
|
86
|
-
end
|
|
87
|
-
end ## method patch_pages
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
def sanitize_pages
|
|
91
|
-
## for debugging/testing lets you (re)run sanitize (alreay incl. in html2txt filter by default)
|
|
92
|
-
sanitize_dir( "#{@repo_path}/tables" )
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def make_schedules( cfg )
|
|
98
|
-
|
|
99
|
-
## note: return stats (for report eg. README)
|
|
100
|
-
stats = []
|
|
101
|
-
|
|
102
|
-
files = Dir[ "#{@repo_path}/tables/*.txt" ]
|
|
103
|
-
files.each do |file|
|
|
104
|
-
|
|
105
|
-
## todo/check/fix:
|
|
106
|
-
## use source: prop in rsssf page - why? why not???
|
|
107
|
-
## move year/season/basename into page ???
|
|
108
|
-
#
|
|
109
|
-
# assume every rsssf page has at least:
|
|
110
|
-
## - basename e.g. duit2014
|
|
111
|
-
## - year e.g. 2014 (numeric)
|
|
112
|
-
## - season (derived from config lookup???) - string e.g. 2014-15 or 2014 etc.
|
|
113
|
-
extname = File.extname( file )
|
|
114
|
-
basename = File.basename( file, extname )
|
|
115
|
-
year = year_from_name( basename )
|
|
116
|
-
season = year_to_season( year )
|
|
117
|
-
|
|
118
|
-
if cfg.includes && cfg.includes.include?( year ) == false
|
|
119
|
-
puts " skipping #{basename}; not listed in includes"
|
|
120
|
-
next
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
puts " reading >#{basename}<"
|
|
125
|
-
|
|
126
|
-
page = Page.from_file( file ) # note: always assume sources (already) converted to utf-8
|
|
127
|
-
|
|
128
|
-
if cfg.opts_for_year.is_a?( Hash )
|
|
129
|
-
opts = cfg.opts_for_year ## just use as is 1:1 (constant/same for all years)
|
|
130
|
-
else
|
|
131
|
-
## assume it's a proc/lambda (call to calculate)
|
|
132
|
-
opts = cfg.opts_for_year.call( year )
|
|
133
|
-
end
|
|
134
|
-
pp opts
|
|
135
|
-
|
|
136
|
-
schedule = page.find_schedule( opts )
|
|
137
|
-
## pp schedule
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
if cfg.dir_for_year.nil?
|
|
141
|
-
## use default setting, that is, archive for dir (e.g. archive/1980s/1985-86 etc.)
|
|
142
|
-
dir_for_year = archive_dir_for_year( year )
|
|
143
|
-
else
|
|
144
|
-
## assume it's a proc/lambda
|
|
145
|
-
dir_for_year = cfg.dir_for_year.call( year )
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
## -- cfg.name e.g. => 1-liga
|
|
149
|
-
|
|
150
|
-
dest_path = "#{@repo_path}/#{dir_for_year}/#{cfg.name}.txt"
|
|
151
|
-
puts " save to >#{dest_path}<"
|
|
152
|
-
FileUtils.mkdir_p( File.dirname( dest_path ))
|
|
153
|
-
schedule.save( dest_path )
|
|
154
|
-
|
|
155
|
-
rec = ScheduleStat.new
|
|
156
|
-
rec.path = dir_for_year
|
|
157
|
-
rec.filename = "#{cfg.name}.txt" ## change to basename - why?? why not??
|
|
158
|
-
rec.year = year
|
|
159
|
-
rec.season = season
|
|
160
|
-
rec.rounds = schedule.rounds
|
|
161
|
-
|
|
162
|
-
stats << rec
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
stats # return stats for reporting
|
|
166
|
-
end # method make_schedules
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
private
|
|
170
|
-
def patch_dir( root )
|
|
171
|
-
files = Dir[ "#{root}/*.txt" ]
|
|
172
|
-
## pp files
|
|
173
|
-
|
|
174
|
-
## sort files by year (latest first)
|
|
175
|
-
files = files.sort do |l,r|
|
|
176
|
-
lyear = year_from_file( l )
|
|
177
|
-
ryear = year_from_file( r )
|
|
178
|
-
|
|
179
|
-
ryear <=> lyear
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
files.each do |file|
|
|
183
|
-
txt = File.read_utf8( file ) ## note: assumes already converted to utf-8
|
|
184
|
-
|
|
185
|
-
basename = File.basename( file, '.txt' ) ## e.g. duit92.txt => duit92
|
|
186
|
-
year = year_from_name( basename )
|
|
187
|
-
|
|
188
|
-
new_txt = yield( txt, basename, year )
|
|
189
|
-
## calculate hash to see if anything changed ?? why? why not??
|
|
190
|
-
|
|
191
|
-
File.open( file, 'w' ) do |f|
|
|
192
|
-
f.write new_txt
|
|
193
|
-
end
|
|
194
|
-
end # each file
|
|
195
|
-
end ## patch_dir
|
|
196
|
-
|
|
197
|
-
def sanitize_dir( root )
|
|
198
|
-
files = Dir[ "#{root}/*.txt" ]
|
|
199
|
-
|
|
200
|
-
files.each do |file|
|
|
201
|
-
txt = File.read_utf8( file ) ## note: assumes already converted to utf-8
|
|
202
|
-
|
|
203
|
-
new_txt = sanitize( txt )
|
|
204
|
-
|
|
205
|
-
File.open( file, 'w' ) do |f|
|
|
206
|
-
f.write new_txt
|
|
207
|
-
end
|
|
208
|
-
end # each file
|
|
209
|
-
end ## sanitize_dir
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
end ## class Repo
|
|
213
|
-
end ## module Rsssf
|
|
214
|
-
|
|
215
|
-
## add (shortcut) alias
|
|
216
|
-
RsssfRepo = Rsssf::Repo
|
|
217
|
-
RsssfScheduleConfig = Rsssf::ScheduleConfig
|
|
218
|
-
RsssfScheduleStat = Rsssf::ScheduleStat
|
|
219
|
-
|
|
220
|
-
|
data/test/helper.rb
DELETED
data/test/test_utils.rb
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
|
|
3
|
-
require 'helper'
|
|
4
|
-
|
|
5
|
-
class TestUtils < MiniTest::Test
|
|
6
|
-
|
|
7
|
-
include RsssfUtils ## e.g. year_from_name etc.
|
|
8
|
-
|
|
9
|
-
def test_year
|
|
10
|
-
|
|
11
|
-
###########
|
|
12
|
-
## year_from_name
|
|
13
|
-
## note: num <= 16 - assume 20xx for now from 00..16
|
|
14
|
-
## - else 19xx
|
|
15
|
-
assert_equal 2000, year_from_name( 'duit00' )
|
|
16
|
-
assert_equal 2016, year_from_name( 'duit16' )
|
|
17
|
-
|
|
18
|
-
assert_equal 1999, year_from_name( 'duit99' )
|
|
19
|
-
|
|
20
|
-
assert_equal 2001, year_from_name( 'duit2001' )
|
|
21
|
-
|
|
22
|
-
assert_equal 1964, year_from_name( 'duit64' )
|
|
23
|
-
assert_equal 1965, year_from_name( 'duit1965' )
|
|
24
|
-
assert_equal 2011, year_from_name( 'duit2011' )
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
####
|
|
28
|
-
# year_from_file
|
|
29
|
-
|
|
30
|
-
assert_equal 2000, year_from_file( 'duit00.txt' )
|
|
31
|
-
assert_equal 2000, year_from_file( 'duit00.html' )
|
|
32
|
-
assert_equal 2000, year_from_file( './duit00.txt' )
|
|
33
|
-
assert_equal 2000, year_from_file( 'xxx/1998/xxx/duit00.txt' )
|
|
34
|
-
|
|
35
|
-
assert_equal 2016, year_from_file( 'duit16.txt' )
|
|
36
|
-
assert_equal 2016, year_from_file( 'duit16.html' )
|
|
37
|
-
|
|
38
|
-
assert_equal 2001, year_from_file( 'duit2001.txt' )
|
|
39
|
-
assert_equal 2001, year_from_file( 'duit2001.html' )
|
|
40
|
-
assert_equal 2001, year_from_file( 'xx/1990s/1997/xxx/duit2001.txt' )
|
|
41
|
-
|
|
42
|
-
assert_equal 2000, year_from_file( 'de-deutschland/tables/duit00.txt' )
|
|
43
|
-
assert_equal 1964, year_from_file( 'de-deutschland/62/tables/duit64.txt' ) # check w/ numbers in path
|
|
44
|
-
assert_equal 1999, year_from_file( 'de-deutschland/1977/tables/duit99.txt' ) # check w/ numbers in path
|
|
45
|
-
assert_equal 1965, year_from_file( 'de-deutschland/tables/duit1965.txt' )
|
|
46
|
-
assert_equal 2011, year_from_file( 'de-deutschland/tables/duit2011.txt' )
|
|
47
|
-
|
|
48
|
-
assert_equal 2000, year_from_file( 'de-deutschland/tables/duit00.html' )
|
|
49
|
-
assert_equal 1964, year_from_file( 'de-deutschland/62/tables/duit64.html' ) # check w/ numbers in path
|
|
50
|
-
assert_equal 1999, year_from_file( 'de-deutschland/1977/tables/duit99.html' ) # check w/ numbers in path
|
|
51
|
-
assert_equal 1965, year_from_file( 'de-deutschland/tables/duit1965.html' )
|
|
52
|
-
assert_equal 2011, year_from_file( 'de-deutschland/tables/duit2011.html' )
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
#####
|
|
56
|
-
## year_to_season
|
|
57
|
-
|
|
58
|
-
assert_equal '1998-99', year_to_season( 1999 )
|
|
59
|
-
assert_equal '1999-00', year_to_season( 2000 ) ## todo: use 1999-2000 - why? why not??
|
|
60
|
-
assert_equal '2000-01', year_to_season( 2001 )
|
|
61
|
-
assert_equal '2014-15', year_to_season( 2015 )
|
|
62
|
-
|
|
63
|
-
assert_equal '1999-00', year_to_season( 0 )
|
|
64
|
-
assert_equal '1963-64', year_to_season( 64 )
|
|
65
|
-
assert_equal '1998-99', year_to_season( 99 )
|
|
66
|
-
assert_equal '1964-65', year_to_season( 1965 )
|
|
67
|
-
assert_equal '2010-11', year_to_season( 2011 )
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
#######
|
|
71
|
-
## archive_dir_for_year
|
|
72
|
-
## note: year <= 2010 use season 2009-10
|
|
73
|
-
|
|
74
|
-
assert_equal 'archive/1990s/1998-99', archive_dir_for_year( 1999 )
|
|
75
|
-
assert_equal 'archive/2000s/2000-01', archive_dir_for_year( 2001 )
|
|
76
|
-
assert_equal '2014-15', archive_dir_for_year( 2015 )
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
assert true ## everything ok if get here
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
end # class TestUtils
|
|
83
|
-
|