football-sources 0.0.1

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.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +4 -0
  3. data/Manifest.txt +36 -0
  4. data/README.md +28 -0
  5. data/Rakefile +31 -0
  6. data/lib/football-sources.rb +46 -0
  7. data/lib/football-sources/apis.rb +86 -0
  8. data/lib/football-sources/apis/config.rb +17 -0
  9. data/lib/football-sources/apis/convert.rb +239 -0
  10. data/lib/football-sources/apis/convert_cl.rb +267 -0
  11. data/lib/football-sources/apis/download.rb +11 -0
  12. data/lib/football-sources/apis/stat.rb +59 -0
  13. data/lib/football-sources/version.rb +19 -0
  14. data/lib/football-sources/worldfootball.rb +24 -0
  15. data/lib/football-sources/worldfootball/build.rb +245 -0
  16. data/lib/football-sources/worldfootball/config.rb +16 -0
  17. data/lib/football-sources/worldfootball/convert.rb +100 -0
  18. data/lib/football-sources/worldfootball/convert_reports.rb +107 -0
  19. data/lib/football-sources/worldfootball/download.rb +61 -0
  20. data/lib/football-sources/worldfootball/leagues.rb +200 -0
  21. data/lib/football-sources/worldfootball/leagues/asia.rb +53 -0
  22. data/lib/football-sources/worldfootball/leagues/europe--british_isles.rb +59 -0
  23. data/lib/football-sources/worldfootball/leagues/europe--central.rb +127 -0
  24. data/lib/football-sources/worldfootball/leagues/europe--eastern.rb +82 -0
  25. data/lib/football-sources/worldfootball/leagues/europe--northern.rb +57 -0
  26. data/lib/football-sources/worldfootball/leagues/europe--southern.rb +86 -0
  27. data/lib/football-sources/worldfootball/leagues/europe--western.rb +38 -0
  28. data/lib/football-sources/worldfootball/leagues/europe.rb +13 -0
  29. data/lib/football-sources/worldfootball/leagues/north_america.rb +44 -0
  30. data/lib/football-sources/worldfootball/leagues/pacific.rb +21 -0
  31. data/lib/football-sources/worldfootball/leagues/south_america.rb +11 -0
  32. data/lib/football-sources/worldfootball/mods.rb +72 -0
  33. data/lib/football-sources/worldfootball/tool.rb +100 -0
  34. data/lib/football-sources/worldfootball/vacuum.rb +66 -0
  35. data/lib/football/sources.rb +6 -0
  36. data/test/helper.rb +8 -0
  37. data/test/test_version.rb +16 -0
  38. metadata +147 -0
@@ -0,0 +1,38 @@
1
+
2
+ module Worldfootball
3
+
4
+ LEAGUES_EUROPE.merge!({
5
+ 'fr.1' => { pages: 'fra-ligue-1' },
6
+ 'fr.2' => { pages: 'fra-ligue-2' },
7
+
8
+ # e.g. /lux-nationaldivision-2020-2021/
9
+ 'lu.1' => { pages: 'lux-nationaldivision' },
10
+
11
+ # e.g. /ned-eredivisie-2020-2021/
12
+ 'nl.1' => { pages: 'ned-eredivisie' },
13
+ # Championship play-offs
14
+ # Europa League play-offs (Group A + Group B / Finals )
15
+
16
+ # e.g. /bel-eerste-klasse-a-2020-2021/
17
+ # /bel-europa-league-playoffs-2018-2019-playoff/
18
+ # - Halbfinale
19
+ # - Finale
20
+ 'be.1' => {
21
+ pages: {
22
+ 'bel-eerste-klasse-a-{season}' => 'Regular Season',
23
+ 'bel-eerste-klasse-a-{season}-playoff-i' => 'Playoffs - Championship',
24
+ 'bel-europa-league-playoffs-{season}' => 'Playoffs - Europa League', ## note: missing groups (A & B)
25
+ 'bel-europa-league-playoffs-{season}-playoff' => 'Playoffs - Europa League - Finals',
26
+ },
27
+ season: ->( season ) {
28
+ case season
29
+ when Season('2020/21') then [1] # just getting started
30
+ when Season('2019/20') then [1] # covid-19 - no championship & europa
31
+ when Season('2018/19') then [1,2,3,4]
32
+ end
33
+ }
34
+ },
35
+
36
+ })
37
+
38
+ end
@@ -0,0 +1,13 @@
1
+
2
+ module Worldfootball
3
+ LEAGUES_EUROPE = {}
4
+ end
5
+
6
+
7
+ require_relative 'europe--western'
8
+ require_relative 'europe--british_isles'
9
+ require_relative 'europe--northern'
10
+ require_relative 'europe--central'
11
+ require_relative 'europe--eastern'
12
+ require_relative 'europe--southern'
13
+
@@ -0,0 +1,44 @@
1
+ module Worldfootball
2
+
3
+ LEAGUES_NORTH_AMERICA = {
4
+
5
+ # todo/fix: adjust date/time by -6 or 7 hours!!!
6
+ # /can-canadian-championship-2020/
7
+ # - Qual. 1. Runde
8
+ # - Qual. 2. Runde
9
+ # - Qual. 3. Runde
10
+ # todo/fix: check for leagues - premier league? championship? soccer league?
11
+ # 'ca.1' => { slug: 'can-canadian-championship' },
12
+
13
+
14
+
15
+ # todo/fix: adjust date/time by -7 hours!!!
16
+ ## e.g. 25.07.2020 02:30 => 24.07.2020 19.30
17
+ # 11.01.2020 04:00 => 10.01.2020 21.00
18
+ #
19
+ # e.g. /mex-primera-division-2020-2021-apertura/
20
+ # /mex-primera-division-2019-2020-clausura/
21
+ # /mex-primera-division-2019-2020-apertura-playoffs/
22
+ # - Viertelfinale
23
+ # - Halbfinale
24
+ # - Finale
25
+ # /mex-primera-division-2018-2019-clausura-playoffs/
26
+ 'mx.1' => {
27
+ pages: {
28
+ 'mex-primera-division-{season}-apertura' => 'Apertura', # 1
29
+ 'mex-primera-division-{season}-apertura-playoffs' => 'Apertura - Liguilla', # 2
30
+ 'mex-primera-division-{season}-clausura' => 'Clausura', # 3
31
+ 'mex-primera-division-{season}-clausura-playoffs' => 'Clausura - Liguilla', # 4
32
+ },
33
+ season: ->( season ) {
34
+ case season
35
+ when Season('2020/21') then [1] # just getting started
36
+ when Season('2019/20') then [1,2,3] # covid-19 - no liguilla
37
+ when Season('2010/11')..Season('2018/19') then [1,2,3,4]
38
+ end
39
+ }
40
+ },
41
+ }
42
+
43
+ end # module Worldfootball
44
+
@@ -0,0 +1,21 @@
1
+ module Worldfootball
2
+
3
+ LEAGUES_PACIFIC = {
4
+
5
+ # /nzl-nz-football-championship-2019-2020/
6
+ # /nzl-nz-football-championship-2018-2019-playoffs/
7
+ 'nz.1' => {
8
+ pages: {
9
+ 'nzl-nz-football-championship-{season}' => 'Regular Season', # 1
10
+ 'nzl-nz-football-championship-{season}-playoffs' => 'Playoff Finals', # 2
11
+ },
12
+ season: ->( season ) {
13
+ case season
14
+ when Season('2019/20') then [1] ## covid-19 - no playoffs/finals
15
+ when Season('2018/19') then [1,2]
16
+ end
17
+ }
18
+ },
19
+ }
20
+
21
+ end # module Worldfootball
@@ -0,0 +1,11 @@
1
+ module Worldfootball
2
+
3
+ LEAGUES_SOUTH_AMERICA = {
4
+
5
+ # todo/fix: adjust date/time by -6 or 7 hours!!!
6
+ # /bra-serie-a-2020/
7
+ 'br.1' => { pages: 'bra-serie-a' },
8
+ }
9
+
10
+ end # module Worldfootball
11
+
@@ -0,0 +1,72 @@
1
+ #### todo/check: move MODS and SCORE_ERRORS out-of-lib
2
+ ## and into config or such - why? why not?
3
+
4
+
5
+ module Worldfootball
6
+
7
+
8
+ ######
9
+ # "global" helpers
10
+ def self.norm_team( team )
11
+ ## clean team name and asciify (e.g. ’->' )
12
+ team = team.sub( '(old)', '' ).strip
13
+ team = team.gsub( '’', "'" ) ## e.g. Hawke’s Bay United FC
14
+ team
15
+ end
16
+
17
+
18
+
19
+ MODS = {
20
+ 'at' => {
21
+ ## AT 1
22
+ 'SC Magna Wiener Neustadt' => 'SC Wiener Neustadt', # in 2010/11
23
+ 'KSV Superfund' => 'Kapfenberger SV', # in 2010/11
24
+ 'Kapfenberger SV 1919' => 'Kapfenberger SV', # in 2011/12
25
+ 'FC Trenkwalder Admira' => 'FC Admira Wacker', # in 2011/12
26
+ ## AT 2
27
+ 'Austria Wien (A)' => 'Young Violets', # in 2019/20
28
+ 'FC Wacker Innsbruck (A)' => 'FC Wacker Innsbruck II', # in 2018/19
29
+ ## AT CUP
30
+ 'Rapid Wien (A)' => 'Rapid Wien II', # in 2011/12
31
+ 'Sturm Graz (A)' => 'Sturm Graz II',
32
+ 'Kapfenberger SV 1919 (A)' => 'Kapfenberger SV II',
33
+ 'SV Grödig (A)' => 'SV Grödig II',
34
+ 'RB Salzburg (A)' => 'RB Salzburg II',
35
+ 'SR WGFM Donaufeld' => 'SR Donaufeld Wien',
36
+ 'FC Trenkwalder Admira (A)' => 'FC Admira Wacker II',
37
+ ## AT 3.O (Regionalliga Ost)
38
+ 'FC Admira Wacker (A)' => 'FC Admira Wacker II', # in 2020/21
39
+ },
40
+ 'nz' => {
41
+ ## NZ 1
42
+ 'Wellington Phoenix (R)' => 'Wellington Phoenix Reserves',
43
+ },
44
+ }
45
+
46
+
47
+
48
+ ## fix/patch known score format errors in at/de cups
49
+ ## new convention
50
+ ## for a fix require league, date, and team1 & team2 for now!!!!
51
+ ## - do NOT use some "generic" fix / patch!!!!
52
+ ##
53
+ ## old de/at patches/fixes:
54
+ ## '0-1 (0-0, 0-0, 0-0) n.V.' => '0-1 (0-0, 0-0) n.V.', # too long
55
+ ## '2-1 (1-1, 1-1, 1-0) n.V.' => '2-1 (1-1, 1-1) n.V.',
56
+ ## '4-2 (0-0, 0-0) i.E.' => '4-2 (0-0, 0-0, 0-0) i.E.', # too short
57
+
58
+
59
+ SCORE_ERRORS = {
60
+ 'ro.1' => {
61
+ ## 2013/14
62
+ '2013-07-29' => [ 'FC Brașov', 'Săgeata Năvodari', ['1-1 (0-0, 0-1)', '1-1 (0-0)']],
63
+ },
64
+ 'gr.1' => {
65
+ ## 2010/11
66
+ '2010-11-24' => [ 'Ergotelis', 'Olympiakos Piräus', ['0-2 (0-0, 0-0, 0-0)', '0-2 (0-0)']],
67
+ '2010-11-28' => [ 'Panserraikos', 'Aris Saloniki', ['1-0 (1-0, 0-0, 0-0)', '1-0 (1-0)']],
68
+ }
69
+ }
70
+
71
+
72
+ end # module Worldfootball
@@ -0,0 +1,100 @@
1
+
2
+
3
+ module Worldfootball
4
+ ################################
5
+ # add more helpers
6
+ # move upstream for (re)use - why? why not?
7
+
8
+ ## todo/check: what to do: if league is both included and excluded?
9
+ ## include forces include? or exclude has the last word? - why? why not?
10
+ ## Excludes match before includes,
11
+ ## meaning that something that has been excluded cannot be included again
12
+
13
+ ## todo - find "proper/classic" timezone ("winter time")
14
+
15
+ ## Brasilia - Distrito Federal, Brasil (GMT-3) -- summer time?
16
+ ## Ciudad de México, CDMX, México (GMT-5) -- summer time?
17
+ ## Londres, Reino Unido (GMT+1)
18
+ ## Madrid -- ?
19
+ ## Lisboa -- ?
20
+ ## Moskow -- ?
21
+ ##
22
+ ## todo/check - quick fix timezone offsets for leagues for now
23
+ ## - find something better - why? why not?
24
+ ## note: assume time is in GMT+1
25
+ OFFSETS = {
26
+ 'eng.1' => -1,
27
+ 'eng.2' => -1,
28
+ 'eng.3' => -1,
29
+ 'eng.4' => -1,
30
+ 'eng.5' => -1,
31
+
32
+ 'es.1' => -1,
33
+ 'es.2' => -1,
34
+
35
+ 'pt.1' => -1,
36
+ 'pt.2' => -1,
37
+
38
+ 'br.1' => -5,
39
+ 'mx.1' => -7,
40
+ }
41
+
42
+
43
+
44
+
45
+ class Tool
46
+ def initialize( includes: nil,
47
+ excludes: nil )
48
+ ## quick fix: move/handle empty array upstream!!!!
49
+ includes = nil if includes.is_a?(Array) && includes.empty?
50
+
51
+ @includes = includes
52
+ @excludes = excludes
53
+ end
54
+
55
+
56
+
57
+ def download( datasets )
58
+ datasets.each do |dataset|
59
+ league = dataset[0]
60
+ seasons = dataset[1]
61
+
62
+ with_filter( league ) do
63
+ seasons.each do |season|
64
+ puts "downloading #{league} #{season}..."
65
+
66
+ Worldfootball.schedule( league: league,
67
+ season: season )
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def convert( datasets )
74
+ datasets.each do |dataset|
75
+ league = dataset[0]
76
+ seasons = dataset[1]
77
+
78
+ with_filter( league ) do
79
+ seasons.each do |season|
80
+ Worldfootball.convert( league: league,
81
+ season: season,
82
+ offset: OFFSETS[ league ] )
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+
89
+ #########################################
90
+ # more helpers
91
+ def with_filter( league, &blk )
92
+ return if @excludes && @excludes.find { |q| league.start_with?( q.downcase ) }
93
+ return if @includes && @includes.find { |q| league.start_with?( q.downcase ) }.nil?
94
+ blk.call()
95
+ end
96
+
97
+ end # class Tool
98
+ end # module Worldfootball
99
+
100
+
@@ -0,0 +1,66 @@
1
+ module Worldfootball
2
+
3
+
4
+ MAX_HEADERS = [
5
+ 'Stage',
6
+ 'Round',
7
+ 'Date',
8
+ 'Time',
9
+ 'Team 1',
10
+ 'FT',
11
+ 'HT',
12
+ 'Team 2',
13
+ 'ET',
14
+ 'P',
15
+ 'Comments'] ## e.g. awarded, cancelled/canceled, etc.
16
+
17
+ MIN_HEADERS = [ ## always keep even if all empty
18
+ 'Date',
19
+ 'Team 1',
20
+ 'FT',
21
+ 'Team 2'
22
+ ]
23
+
24
+ def self.vacuum( rows, headers: MAX_HEADERS, fixed_headers: MIN_HEADERS )
25
+ ## check for unused columns and strip/remove
26
+ counter = Array.new( MAX_HEADERS.size, 0 )
27
+ rows.each do |row|
28
+ row.each_with_index do |col, idx|
29
+ counter[idx] += 1 unless col.nil? || col.empty?
30
+ end
31
+ end
32
+
33
+ pp counter
34
+
35
+ ## check empty columns
36
+ headers = []
37
+ indices = []
38
+ empty_headers = []
39
+ empty_indices = []
40
+
41
+ counter.each_with_index do |num, idx|
42
+ header = MAX_HEADERS[ idx ]
43
+ if num > 0 || (num == 0 && fixed_headers.include?( header ))
44
+ headers << header
45
+ indices << idx
46
+ else
47
+ empty_headers << header
48
+ empty_indices << idx
49
+ end
50
+ end
51
+
52
+ if empty_indices.size > 0
53
+ rows = rows.map do |row|
54
+ row_vacuumed = []
55
+ row.each_with_index do |col, idx|
56
+ ## todo/fix: use values or such??
57
+ row_vacuumed << col unless empty_indices.include?( idx )
58
+ end
59
+ row_vacuumed
60
+ end
61
+ end
62
+
63
+ [rows, headers]
64
+ end
65
+
66
+ end # module Worldfootball
@@ -0,0 +1,6 @@
1
+ # note: allow require 'football/sources' too
2
+ # (in addition to require 'football-sources')
3
+
4
+ require_relative '../football-sources'
5
+
6
+
@@ -0,0 +1,8 @@
1
+ $LOAD_PATH.unshift( '../webget/lib')
2
+
3
+ require 'minitest/autorun'
4
+
5
+
6
+ ## our own code
7
+ require 'football/sources' ## or require 'football-sources'
8
+
@@ -0,0 +1,16 @@
1
+ ###
2
+ # to run use
3
+ # ruby -I ./lib -I ./test test/test_version.rb
4
+
5
+
6
+ require 'helper'
7
+
8
+ class TestVersion < MiniTest::Test
9
+
10
+ def test_version
11
+ pp FootballSources::VERSION
12
+ pp FootballSources.banner
13
+ pp FootballSources.root
14
+ end
15
+
16
+ end # class TestVersion
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: football-sources
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webget-football
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: sportdb-catalogs
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.0.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.0.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ - - "<"
49
+ - !ruby/object:Gem::Version
50
+ version: '7'
51
+ type: :development
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '4.0'
58
+ - - "<"
59
+ - !ruby/object:Gem::Version
60
+ version: '7'
61
+ - !ruby/object:Gem::Dependency
62
+ name: hoe
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.22'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '3.22'
75
+ description: football-sources - get football data via web pages or web api (json)
76
+ calls
77
+ email: opensport@googlegroups.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files:
81
+ - CHANGELOG.md
82
+ - Manifest.txt
83
+ - README.md
84
+ files:
85
+ - CHANGELOG.md
86
+ - Manifest.txt
87
+ - README.md
88
+ - Rakefile
89
+ - lib/football-sources.rb
90
+ - lib/football-sources/apis.rb
91
+ - lib/football-sources/apis/config.rb
92
+ - lib/football-sources/apis/convert.rb
93
+ - lib/football-sources/apis/convert_cl.rb
94
+ - lib/football-sources/apis/download.rb
95
+ - lib/football-sources/apis/stat.rb
96
+ - lib/football-sources/version.rb
97
+ - lib/football-sources/worldfootball.rb
98
+ - lib/football-sources/worldfootball/build.rb
99
+ - lib/football-sources/worldfootball/config.rb
100
+ - lib/football-sources/worldfootball/convert.rb
101
+ - lib/football-sources/worldfootball/convert_reports.rb
102
+ - lib/football-sources/worldfootball/download.rb
103
+ - lib/football-sources/worldfootball/leagues.rb
104
+ - lib/football-sources/worldfootball/leagues/asia.rb
105
+ - lib/football-sources/worldfootball/leagues/europe--british_isles.rb
106
+ - lib/football-sources/worldfootball/leagues/europe--central.rb
107
+ - lib/football-sources/worldfootball/leagues/europe--eastern.rb
108
+ - lib/football-sources/worldfootball/leagues/europe--northern.rb
109
+ - lib/football-sources/worldfootball/leagues/europe--southern.rb
110
+ - lib/football-sources/worldfootball/leagues/europe--western.rb
111
+ - lib/football-sources/worldfootball/leagues/europe.rb
112
+ - lib/football-sources/worldfootball/leagues/north_america.rb
113
+ - lib/football-sources/worldfootball/leagues/pacific.rb
114
+ - lib/football-sources/worldfootball/leagues/south_america.rb
115
+ - lib/football-sources/worldfootball/mods.rb
116
+ - lib/football-sources/worldfootball/tool.rb
117
+ - lib/football-sources/worldfootball/vacuum.rb
118
+ - lib/football/sources.rb
119
+ - test/helper.rb
120
+ - test/test_version.rb
121
+ homepage: https://github.com/sportdb/sport.db
122
+ licenses:
123
+ - Public Domain
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options:
127
+ - "--main"
128
+ - README.md
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.2.2
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.5.2
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: football-sources - get football data via web pages or web api (json) calls
147
+ test_files: []