openliga 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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +4 -0
- data/Manifest.txt +18 -0
- data/README.md +225 -0
- data/Rakefile +33 -0
- data/bin/openliga +14 -0
- data/config/leagues_de.csv +65 -0
- data/config/leagues_more.csv +43 -0
- data/lib/openliga/convert-goals.rb +62 -0
- data/lib/openliga/convert-match.rb +94 -0
- data/lib/openliga/convert-score.rb +172 -0
- data/lib/openliga/convert.rb +68 -0
- data/lib/openliga/convert_helpers.rb +73 -0
- data/lib/openliga/download.rb +81 -0
- data/lib/openliga/leagues.rb +45 -0
- data/lib/openliga/models.rb +153 -0
- data/lib/openliga/pp_matches.rb +146 -0
- data/lib/openliga/tool.rb +138 -0
- data/lib/openliga.rb +26 -0
- metadata +142 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
|
|
2
|
+
module Openliga
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
def self.pp_matches( matches )
|
|
6
|
+
|
|
7
|
+
buf = String.new
|
|
8
|
+
|
|
9
|
+
last_round = nil
|
|
10
|
+
last_year = nil
|
|
11
|
+
last_date = nil
|
|
12
|
+
last_time = nil
|
|
13
|
+
|
|
14
|
+
matches.each do |m|
|
|
15
|
+
## add stage/round/group header
|
|
16
|
+
if last_round.nil? || last_round != m.round
|
|
17
|
+
buf << "\n▪ #{m.round}\n"
|
|
18
|
+
last_date = nil
|
|
19
|
+
last_time = nil
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
## add date header
|
|
23
|
+
if last_date.nil? || last_date != m.date
|
|
24
|
+
## note - only print year (on first time or if changed to new year)
|
|
25
|
+
if last_year.nil? || last_year != m.date.year
|
|
26
|
+
buf << "#{m.date.strftime('%a %b %-d %Y')}\n"
|
|
27
|
+
else
|
|
28
|
+
buf << "#{m.date.strftime('%a %b %-d')}\n"
|
|
29
|
+
end
|
|
30
|
+
last_time = nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
line = String.new
|
|
35
|
+
|
|
36
|
+
if m.time
|
|
37
|
+
if last_time && last_time == m.time
|
|
38
|
+
line << " " ## note - do NOT repeat time if same as last
|
|
39
|
+
else
|
|
40
|
+
line << " #{m.time}"
|
|
41
|
+
end
|
|
42
|
+
else
|
|
43
|
+
line << ' '
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
line << " %-24s v %-24s" % [m.team1, m.team2]
|
|
47
|
+
line << " #{m.score.to_s}" if m.score
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if m.ground || m.city
|
|
51
|
+
geo = [m.ground, m.city].compact ## remove nils
|
|
52
|
+
|
|
53
|
+
## maybe use "smart" < -- if comma used already in ground
|
|
54
|
+
line << " @ #{geo.join(', ')}"
|
|
55
|
+
## only add attendance if stadium - why? why not
|
|
56
|
+
if m.att && m.att > 0
|
|
57
|
+
line << ", Att: #{m.att}"
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
buf << line.rstrip ## note - remove trailing spaces
|
|
62
|
+
buf << "\n"
|
|
63
|
+
|
|
64
|
+
####
|
|
65
|
+
## check for goals
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if m.goals.is_a?(Array) && m.goals.size > 0
|
|
69
|
+
|
|
70
|
+
## note - filter out penalties from penalty shootout
|
|
71
|
+
## SG Sonnenhof Großaspach v DSC Arminia Bielefeld 2-2 aet (2-2, 1-2), 5-2 pen
|
|
72
|
+
## (3-2 Arbnor Nuraj (p)
|
|
73
|
+
## 4-2 Luca Molinari (p)
|
|
74
|
+
## 5-2 Franz Xaver Bleicher (p)
|
|
75
|
+
|
|
76
|
+
goals = if m.score && m.score.et? && m.score.pen?
|
|
77
|
+
m.goals.select do |goal|
|
|
78
|
+
if goal.score[0] <= m.score.et[0] &&
|
|
79
|
+
goal.score[1] <= m.score.et[1]
|
|
80
|
+
true
|
|
81
|
+
else
|
|
82
|
+
puts "!! WARN - ignoring penalty shootout goal - #{goal.to_s}"
|
|
83
|
+
false
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
else
|
|
87
|
+
m.goals
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
###
|
|
91
|
+
## check if goals have any player names or minutes
|
|
92
|
+
## if none - skip print of goals
|
|
93
|
+
has_goal_details = false
|
|
94
|
+
goals.each do |goal|
|
|
95
|
+
if goal.name || goal.m
|
|
96
|
+
has_goal_details = true
|
|
97
|
+
break
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
if has_goal_details
|
|
104
|
+
|
|
105
|
+
###
|
|
106
|
+
### note - sort goals first (might not be in order!)
|
|
107
|
+
## use total of goals e.g. [0,1] => 1 [2,2] => 4 etc.
|
|
108
|
+
|
|
109
|
+
goals = goals.sort do |l,r|
|
|
110
|
+
l_sum = l.score[0]+l.score[1]
|
|
111
|
+
r_sum = r.score[0]+r.score[1]
|
|
112
|
+
l_sum <=> r_sum
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
goals.each_with_index do |goal,i|
|
|
116
|
+
line = String.new
|
|
117
|
+
|
|
118
|
+
if i == 0
|
|
119
|
+
line << " ("
|
|
120
|
+
else
|
|
121
|
+
line << " "
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
line << goal.to_s
|
|
125
|
+
|
|
126
|
+
line << ")" if i+1 == goals.size
|
|
127
|
+
|
|
128
|
+
buf << line
|
|
129
|
+
buf << "\n"
|
|
130
|
+
end
|
|
131
|
+
else
|
|
132
|
+
puts "!! WARN - skipping goals line w/o details (name, minute, etc.)"
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
last_round = m.round
|
|
139
|
+
last_year = m.date.year
|
|
140
|
+
last_date = m.date
|
|
141
|
+
last_time = m.time
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
buf
|
|
145
|
+
end
|
|
146
|
+
end ## module Openliga
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
|
|
2
|
+
module Openliga
|
|
3
|
+
module Tool
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def self.main( args=ARGV )
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## todo - make it an option - maybe??
|
|
10
|
+
Webcache.root = './cache'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
opts = {
|
|
14
|
+
metal: false,
|
|
15
|
+
season: nil,
|
|
16
|
+
outpath: nil,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
parser = OptionParser.new do |parser|
|
|
22
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options] NAME"
|
|
23
|
+
|
|
24
|
+
parser.on( "--metal",
|
|
25
|
+
"use openligadb.de shortcuts/codes and seasons/years (default: #{opts[:metal]})" ) do |metal|
|
|
26
|
+
opts[:metal] = true
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
parser.on( "-o PATH", "--output",
|
|
30
|
+
"write football.txt conversion to output path (default: #{opts[:outpath]||'none'})" ) do |outpath|
|
|
31
|
+
opts[:outpath] = outpath
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
parser.on( "--season=SEASON",
|
|
35
|
+
"season (default: #{opts[:season]||'none'})" ) do |season|
|
|
36
|
+
opts[:season] = season
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
parser.parse!( args )
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
puts "OPTS:"
|
|
43
|
+
pp opts
|
|
44
|
+
puts "ARGV:"
|
|
45
|
+
pp args
|
|
46
|
+
|
|
47
|
+
if args.size == 0
|
|
48
|
+
puts " NAME argument required; use:"
|
|
49
|
+
pp LEAGUES
|
|
50
|
+
puts "---"
|
|
51
|
+
pp LEAGUES.keys
|
|
52
|
+
exit 1
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
##
|
|
58
|
+
## note - all args other than first ignored for now; issue warn - why? why not?
|
|
59
|
+
|
|
60
|
+
code = nil
|
|
61
|
+
year = nil
|
|
62
|
+
info = nil
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if opts[:metal]
|
|
66
|
+
code = args[0]
|
|
67
|
+
year = opts[:season] ? opts[:season].to_i(10) : Time.now.year
|
|
68
|
+
|
|
69
|
+
pp [code,year]
|
|
70
|
+
else
|
|
71
|
+
key = args[0].downcase
|
|
72
|
+
seasons = LEAGUES[key]
|
|
73
|
+
|
|
74
|
+
if seasons.nil?
|
|
75
|
+
puts "!! ERROR - no league (info) found for key >#{key}<; known keys include:"
|
|
76
|
+
pp LEAGUES.keys
|
|
77
|
+
exit 1
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
season_key = if opts[:season]
|
|
81
|
+
Season.parse(opts[:season]).to_key
|
|
82
|
+
else
|
|
83
|
+
seasons.keys[0] ## autopick latest
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
info = seasons[season_key]
|
|
87
|
+
|
|
88
|
+
if info.nil?
|
|
89
|
+
puts "!! ERROR - no season >#{season_key}< found for league with key >#{key}<; known seasons include:"
|
|
90
|
+
pp seasons.keys
|
|
91
|
+
exit 1
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
pp info
|
|
95
|
+
|
|
96
|
+
code = info.shortcut
|
|
97
|
+
year = info.season
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
#############
|
|
102
|
+
### step 1 - download
|
|
103
|
+
puts "==> downloading /getmatchdata/#{code}/#{year}"
|
|
104
|
+
data = Metal.matches( code, year )
|
|
105
|
+
|
|
106
|
+
puts " #{data.size} match(es)"
|
|
107
|
+
pp data[0] ## dump first match
|
|
108
|
+
|
|
109
|
+
##################
|
|
110
|
+
### step 2 - convert to football.txt
|
|
111
|
+
|
|
112
|
+
body = Openliga._convert( data )
|
|
113
|
+
|
|
114
|
+
## add header
|
|
115
|
+
###
|
|
116
|
+
### auto-add header
|
|
117
|
+
### note - use leagueName from first match
|
|
118
|
+
header =<<TXT
|
|
119
|
+
###
|
|
120
|
+
# converted from openligadb.de json to Football.TXT
|
|
121
|
+
# for source, see https://api.openligadb.de/getmatchdata/#{code}/#{year}
|
|
122
|
+
|
|
123
|
+
= #{data[0]['leagueName']}
|
|
124
|
+
TXT
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
puts header+body
|
|
128
|
+
|
|
129
|
+
if opts[:outpath]
|
|
130
|
+
puts " writing football.txt to >#{opts[:outpath]}<"
|
|
131
|
+
write_text( opts[:outpath], header+body )
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
puts "bye"
|
|
135
|
+
end ## self.main
|
|
136
|
+
|
|
137
|
+
end ## module Tool
|
|
138
|
+
end ## module Openliga
|
data/lib/openliga.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
## 3rd party (our own)
|
|
2
|
+
require 'season/formats' ## add season support
|
|
3
|
+
require 'webget' ## incl. webget, webcache, webclient, etc.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
###
|
|
8
|
+
# our own code
|
|
9
|
+
require_relative 'openliga/leagues'
|
|
10
|
+
require_relative 'openliga/download'
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
require_relative 'openliga/models'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
require_relative 'openliga/convert'
|
|
17
|
+
require_relative 'openliga/convert_helpers'
|
|
18
|
+
require_relative 'openliga/convert-match'
|
|
19
|
+
require_relative 'openliga/convert-score'
|
|
20
|
+
require_relative 'openliga/convert-goals'
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
require_relative 'openliga/pp_matches'
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
require_relative 'openliga/tool'
|
metadata
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: openliga
|
|
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: 2026-08-28 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: cocos
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: season-formats
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :runtime
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: webget
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
- !ruby/object:Gem::Dependency
|
|
56
|
+
name: rdoc
|
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '4.0'
|
|
62
|
+
- - "<"
|
|
63
|
+
- !ruby/object:Gem::Version
|
|
64
|
+
version: '7'
|
|
65
|
+
type: :development
|
|
66
|
+
prerelease: false
|
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: '4.0'
|
|
72
|
+
- - "<"
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '7'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: hoe
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - "~>"
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '4.2'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - "~>"
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '4.2'
|
|
89
|
+
description: openliga - openligadb.de api client/wrapper and football.txt format converter
|
|
90
|
+
email: gerald.bauer@gmail.com
|
|
91
|
+
executables:
|
|
92
|
+
- openliga
|
|
93
|
+
extensions: []
|
|
94
|
+
extra_rdoc_files:
|
|
95
|
+
- CHANGELOG.md
|
|
96
|
+
- Manifest.txt
|
|
97
|
+
- README.md
|
|
98
|
+
files:
|
|
99
|
+
- CHANGELOG.md
|
|
100
|
+
- Manifest.txt
|
|
101
|
+
- README.md
|
|
102
|
+
- Rakefile
|
|
103
|
+
- bin/openliga
|
|
104
|
+
- config/leagues_de.csv
|
|
105
|
+
- config/leagues_more.csv
|
|
106
|
+
- lib/openliga.rb
|
|
107
|
+
- lib/openliga/convert-goals.rb
|
|
108
|
+
- lib/openliga/convert-match.rb
|
|
109
|
+
- lib/openliga/convert-score.rb
|
|
110
|
+
- lib/openliga/convert.rb
|
|
111
|
+
- lib/openliga/convert_helpers.rb
|
|
112
|
+
- lib/openliga/download.rb
|
|
113
|
+
- lib/openliga/leagues.rb
|
|
114
|
+
- lib/openliga/models.rb
|
|
115
|
+
- lib/openliga/pp_matches.rb
|
|
116
|
+
- lib/openliga/tool.rb
|
|
117
|
+
homepage: https://github.com/sportdb/sport.db
|
|
118
|
+
licenses:
|
|
119
|
+
- Public Domain
|
|
120
|
+
metadata: {}
|
|
121
|
+
post_install_message:
|
|
122
|
+
rdoc_options:
|
|
123
|
+
- "--main"
|
|
124
|
+
- README.md
|
|
125
|
+
require_paths:
|
|
126
|
+
- lib
|
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
|
+
requirements:
|
|
129
|
+
- - ">="
|
|
130
|
+
- !ruby/object:Gem::Version
|
|
131
|
+
version: 3.1.0
|
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
|
+
requirements:
|
|
134
|
+
- - ">="
|
|
135
|
+
- !ruby/object:Gem::Version
|
|
136
|
+
version: '0'
|
|
137
|
+
requirements: []
|
|
138
|
+
rubygems_version: 3.5.22
|
|
139
|
+
signing_key:
|
|
140
|
+
specification_version: 4
|
|
141
|
+
summary: openliga - openligadb.de api client/wrapper and football.txt format converter
|
|
142
|
+
test_files: []
|