football-sources 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +6 -4
- data/Manifest.txt +2 -20
- data/README.md +30 -169
- data/Rakefile +36 -31
- data/bin/fbgen +131 -0
- data/lib/football/sources.rb +6 -6
- data/lib/football-sources/process.rb +68 -0
- data/lib/football-sources/version.rb +19 -19
- data/lib/football-sources.rb +21 -57
- metadata +51 -40
- data/lib/football-sources/apis/config.rb +0 -17
- data/lib/football-sources/apis/convert.rb +0 -239
- data/lib/football-sources/apis/convert_cl.rb +0 -267
- data/lib/football-sources/apis/mods.rb +0 -20
- data/lib/football-sources/apis/stat.rb +0 -59
- data/lib/football-sources/apis.rb +0 -10
- data/lib/football-sources/fbref/build.rb +0 -96
- data/lib/football-sources/fbref/config.rb +0 -16
- data/lib/football-sources/fbref/convert.rb +0 -95
- data/lib/football-sources/fbref.rb +0 -4
- data/lib/football-sources/worldfootball/build.rb +0 -245
- data/lib/football-sources/worldfootball/config.rb +0 -16
- data/lib/football-sources/worldfootball/convert.rb +0 -100
- data/lib/football-sources/worldfootball/convert_reports.rb +0 -107
- data/lib/football-sources/worldfootball/jobs.rb +0 -76
- data/lib/football-sources/worldfootball/mods.rb +0 -72
- data/lib/football-sources/worldfootball/vacuum.rb +0 -66
- data/lib/football-sources/worldfootball.rb +0 -19
- data/test/helper.rb +0 -8
- data/test/test_version.rb +0 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 42b02267a8c37a2b3a38662941d13ac8e61e622c8b45dc0c06a28453e272b2dc
|
4
|
+
data.tar.gz: e26f5cf47b6c0390b4f5d99b85919852eb46e7822201e4d6eba52315dc683e44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24038df8393a7ab1635cd6a5a9376e20c29ba077fbe3db63a917a5f59154aec50c1f6f99c68e1f51cbbd1c28ce07412e89387ae9576e8fc22c2bc872df689ae0
|
7
|
+
data.tar.gz: d27328142ffed18c30078e66c5a313a9df7a12be714401cba36cfa6752c08d0f1c158a796e87c50202ba08ae5ab2212061db494982656b378c3374c3e1cd23c5
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -2,26 +2,8 @@ CHANGELOG.md
|
|
2
2
|
Manifest.txt
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
|
+
bin/fbgen
|
5
6
|
lib/football-sources.rb
|
6
|
-
lib/football-sources/
|
7
|
-
lib/football-sources/apis/config.rb
|
8
|
-
lib/football-sources/apis/convert.rb
|
9
|
-
lib/football-sources/apis/convert_cl.rb
|
10
|
-
lib/football-sources/apis/mods.rb
|
11
|
-
lib/football-sources/apis/stat.rb
|
12
|
-
lib/football-sources/fbref.rb
|
13
|
-
lib/football-sources/fbref/build.rb
|
14
|
-
lib/football-sources/fbref/config.rb
|
15
|
-
lib/football-sources/fbref/convert.rb
|
7
|
+
lib/football-sources/process.rb
|
16
8
|
lib/football-sources/version.rb
|
17
|
-
lib/football-sources/worldfootball.rb
|
18
|
-
lib/football-sources/worldfootball/build.rb
|
19
|
-
lib/football-sources/worldfootball/config.rb
|
20
|
-
lib/football-sources/worldfootball/convert.rb
|
21
|
-
lib/football-sources/worldfootball/convert_reports.rb
|
22
|
-
lib/football-sources/worldfootball/jobs.rb
|
23
|
-
lib/football-sources/worldfootball/mods.rb
|
24
|
-
lib/football-sources/worldfootball/vacuum.rb
|
25
9
|
lib/football/sources.rb
|
26
|
-
test/helper.rb
|
27
|
-
test/test_version.rb
|
data/README.md
CHANGED
@@ -1,169 +1,30 @@
|
|
1
|
-
# football-sources - get football data via web pages or web api (json) calls
|
2
|
-
|
3
|
-
|
4
|
-
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
5
|
-
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
6
|
-
* gem :: [rubygems.org/gems/football-sources](https://rubygems.org/gems/football-sources)
|
7
|
-
* rdoc :: [rubydoc.info/gems/football-sources](http://rubydoc.info/gems/football-sources)
|
8
|
-
* forum :: [groups.google.com/group/opensport](https://groups.google.com/group/opensport)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
## Usage
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
**Step 1 - Download Match Schedules**
|
34
|
-
|
35
|
-
Download the match schedules (in json) via api calls
|
36
|
-
to your (local) web cache (in `~/.cache`).
|
37
|
-
Note: The free trier has a 10 request/minute limit,
|
38
|
-
thus, sleep/wait 10 secs after every request
|
39
|
-
(should result in ~6 requests/minute).
|
40
|
-
|
41
|
-
|
42
|
-
``` ruby
|
43
|
-
require 'football/sources'
|
44
|
-
|
45
|
-
|
46
|
-
# download up (ongoing) 2020 or 2020/21 seasons
|
47
|
-
Webget.config.sleep = 10
|
48
|
-
|
49
|
-
Footballdata.schedule( league: 'eng.1', season: '2020/21' )
|
50
|
-
Footballdata.schedule( league: 'eng.2', season: '2020/21' )
|
51
|
-
|
52
|
-
Footballdata.schedule( league: 'de.1', season: '2020/21' )
|
53
|
-
Footballdata.schedule( league: 'es.1', season: '2020/21' )
|
54
|
-
|
55
|
-
Footballdata.schedule( league: 'fr.1', season: '2020/21' )
|
56
|
-
Footballdata.schedule( league: 'it.1', season: '2020/21' )
|
57
|
-
|
58
|
-
Footballdata.schedule( league: 'nl.1', season: '2020/21' )
|
59
|
-
Footballdata.schedule( league: 'pt.1', season: '2020/21' )
|
60
|
-
|
61
|
-
Footballdata.schedule( league: 'cl', season: '2020/21' )
|
62
|
-
|
63
|
-
# note: Brasileirão - season is a calendar year (NOT an academic year)
|
64
|
-
Footballdata.schedule( league: 'br.1', season: '2020' )
|
65
|
-
```
|
66
|
-
|
67
|
-
Note: You can find all downloaded match schedules
|
68
|
-
in your (local) web cache (in `~/.cache/api.football-data.org`) as pretty printed json documents.
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
**Step 2 - Convert (Cached) Match Schedules to Records**
|
74
|
-
|
75
|
-
Convert the (cached) match schedules
|
76
|
-
in JSON to the one-line, one-match & one-file, one-season
|
77
|
-
"standard" [Football.CSV format](https://github.com/footballcsv). Example:
|
78
|
-
|
79
|
-
``` ruby
|
80
|
-
require 'football/sources'
|
81
|
-
|
82
|
-
['eng.1', 'eng.2',
|
83
|
-
'de.1',
|
84
|
-
'es.1',
|
85
|
-
'fr.1',
|
86
|
-
'it.1',
|
87
|
-
'nl.1',
|
88
|
-
'pt.1',
|
89
|
-
'cl',
|
90
|
-
].each do |league|
|
91
|
-
Footballdata.convert( league: league, season: '2020/21' )
|
92
|
-
end
|
93
|
-
|
94
|
-
Footballdata.convert( league: 'br.1', season: '2020' )
|
95
|
-
```
|
96
|
-
|
97
|
-
Note: By default all datasets get written into the `./o`
|
98
|
-
directory. Use `Footballdata.config.convert.out_dir`
|
99
|
-
to change the output directory.
|
100
|
-
|
101
|
-
The English Premier League (`eng.1`) results in `./o/2020-21/eng.1.csv`:
|
102
|
-
|
103
|
-
```
|
104
|
-
Matchday,Date,Team 1,FT,HT,Team 2,Comments
|
105
|
-
1,Sun Sep 13 2020,Manchester City FC,(*),,Aston Villa FC,postponed
|
106
|
-
1,Sun Sep 13 2020,Burnley FC,(*),,Manchester United FC,postponed
|
107
|
-
1,Sat Sep 12 2020,Fulham FC,0-3,0-1,Arsenal FC,
|
108
|
-
1,Sat Sep 12 2020,Crystal Palace FC,1-0,1-0,Southampton FC,
|
109
|
-
1,Sat Sep 12 2020,Liverpool FC,4-3,3-2,Leeds United FC,
|
110
|
-
1,Sat Sep 12 2020,West Ham United FC,0-2,0-0,Newcastle United FC,
|
111
|
-
1,Sun Sep 13 2020,West Bromwich Albion FC,0-3,0-0,Leicester City FC,
|
112
|
-
1,Sun Sep 13 2020,Tottenham Hotspur FC,0-1,0-0,Everton FC,
|
113
|
-
1,Mon Sep 14 2020,Sheffield United FC,0-2,0-2,Wolverhampton Wanderers FC,
|
114
|
-
1,Mon Sep 14 2020,Brighton & Hove Albion FC,1-3,0-1,Chelsea FC,
|
115
|
-
2,Sat Sep 19 2020,Everton FC,5-2,2-1,West Bromwich Albion FC,
|
116
|
-
2,Sat Sep 19 2020,Leeds United FC,4-3,2-1,Fulham FC,
|
117
|
-
2,Sat Sep 19 2020,Manchester United FC,1-3,0-1,Crystal Palace FC,
|
118
|
-
2,Sat Sep 19 2020,Arsenal FC,2-1,1-1,West Ham United FC,
|
119
|
-
2,Sun Sep 20 2020,Southampton FC,2-5,1-1,Tottenham Hotspur FC,
|
120
|
-
2,Sun Sep 20 2020,Newcastle United FC,0-3,0-2,Brighton & Hove Albion FC,
|
121
|
-
2,Sun Sep 20 2020,Chelsea FC,0-2,0-0,Liverpool FC,
|
122
|
-
2,Sun Sep 20 2020,Leicester City FC,4-2,1-1,Burnley FC,
|
123
|
-
2,Mon Sep 21 2020,Aston Villa FC,1-0,0-0,Sheffield United FC,
|
124
|
-
2,Mon Sep 21 2020,Wolverhampton Wanderers FC,1-3,0-2,Manchester City FC,
|
125
|
-
...
|
126
|
-
```
|
127
|
-
|
128
|
-
Or the Brasileirão (`br.1`) in `./o/2020/br.1.csv`:
|
129
|
-
|
130
|
-
```
|
131
|
-
Matchday,Date,Team 1,FT,HT,Team 2,Comments
|
132
|
-
1,Sat Aug 8 2020,Fortaleza EC,0-2,0-2,CA Paranaense,
|
133
|
-
1,Sat Aug 8 2020,Coritiba FBC,0-1,0-0,SC Internacional,
|
134
|
-
1,Sun Aug 9 2020,SC Recife,3-2,3-1,Ceará SC,
|
135
|
-
1,Sun Aug 9 2020,Santos FC,1-1,0-0,RB Bragantino,
|
136
|
-
1,Sun Aug 9 2020,CR Flamengo,0-1,0-1,CA Mineiro,
|
137
|
-
1,Sun Aug 9 2020,Goiás EC,(*),,São Paulo FC,postponed
|
138
|
-
1,Sun Aug 9 2020,Grêmio FBPA,1-0,1-0,Fluminense FC,
|
139
|
-
1,Sun Aug 9 2020,SE Palmeiras,(*),,CR Vasco da Gama,postponed
|
140
|
-
2,Wed Aug 12 2020,CA Mineiro,3-2,0-2,SC Corinthians Paulista,
|
141
|
-
2,Wed Aug 12 2020,CA Paranaense,2-1,1-1,Goiás EC,
|
142
|
-
2,Wed Aug 12 2020,RB Bragantino,1-1,1-0,Botafogo FR,
|
143
|
-
2,Wed Aug 12 2020,AC Goianiense,3-0,2-0,CR Flamengo,
|
144
|
-
2,Wed Aug 12 2020,EC Bahia,1-0,1-0,Coritiba FBC,
|
145
|
-
2,Thu Aug 13 2020,Fluminense FC,1-1,1-1,SE Palmeiras,
|
146
|
-
2,Thu Aug 13 2020,Ceará SC,1-1,1-0,Grêmio FBPA,
|
147
|
-
2,Thu Aug 13 2020,São Paulo FC,1-0,1-0,Fortaleza EC,
|
148
|
-
2,Thu Aug 13 2020,SC Internacional,2-0,0-0,Santos FC,
|
149
|
-
2,Thu Aug 13 2020,CR Vasco da Gama,2-0,2-0,SC Recife,
|
150
|
-
...
|
151
|
-
```
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
That's it for now. More sources upcoming.
|
156
|
-
|
157
|
-
## License
|
158
|
-
|
159
|
-
![](https://publicdomainworks.github.io/buttons/zero88x31.png)
|
160
|
-
|
161
|
-
The `football-sources` scripts are dedicated to the public domain.
|
162
|
-
Use it as you please with no restrictions whatsoever.
|
163
|
-
|
164
|
-
|
165
|
-
## Questions? Comments?
|
166
|
-
|
167
|
-
Send them along to the
|
168
|
-
[Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
|
169
|
-
Thanks!
|
1
|
+
# football-sources - get football match data (leagues, cups & more) via web pages or web api (json) calls
|
2
|
+
|
3
|
+
|
4
|
+
* home :: [github.com/sportdb/sport.db](https://github.com/sportdb/sport.db)
|
5
|
+
* bugs :: [github.com/sportdb/sport.db/issues](https://github.com/sportdb/sport.db/issues)
|
6
|
+
* gem :: [rubygems.org/gems/football-sources](https://rubygems.org/gems/football-sources)
|
7
|
+
* rdoc :: [rubydoc.info/gems/football-sources](http://rubydoc.info/gems/football-sources)
|
8
|
+
* forum :: [groups.google.com/group/opensport](https://groups.google.com/group/opensport)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
|
15
|
+
To be done.
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
## License
|
20
|
+
|
21
|
+
|
22
|
+
The `football-sources` scripts are dedicated to the public domain.
|
23
|
+
Use it as you please with no restrictions whatsoever.
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
## Questions? Comments?
|
28
|
+
|
29
|
+
Yes, you can. More than welcome.
|
30
|
+
See [Help & Support »](https://github.com/openfootball/help)
|
data/Rakefile
CHANGED
@@ -1,31 +1,36 @@
|
|
1
|
-
require 'hoe'
|
2
|
-
require './lib/football-sources/version.rb'
|
3
|
-
|
4
|
-
Hoe.spec 'football-sources' do
|
5
|
-
|
6
|
-
self.version = FootballSources::VERSION
|
7
|
-
|
8
|
-
self.summary = 'football-sources - get football data via web pages or web api (json) calls'
|
9
|
-
self.description = summary
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
self.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
self.
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/football-sources/version.rb'
|
3
|
+
|
4
|
+
Hoe.spec 'football-sources' do
|
5
|
+
|
6
|
+
self.version = FootballSources::VERSION
|
7
|
+
|
8
|
+
self.summary = 'football-sources - get football match data (leagues, cups & more) via web pages or web api (json) calls'
|
9
|
+
self.description = summary
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
self.urls = { home: 'https://github.com/sportdb/sport.db' }
|
14
|
+
|
15
|
+
self.author = 'Gerald Bauer'
|
16
|
+
self.email = 'gerald.bauer@gmail.com'
|
17
|
+
|
18
|
+
# switch extension to .markdown for gihub formatting
|
19
|
+
self.readme_file = 'README.md'
|
20
|
+
self.history_file = 'CHANGELOG.md'
|
21
|
+
|
22
|
+
self.extra_deps = [
|
23
|
+
['sportdb-catalogs'], #, '>= 1.0.0'],
|
24
|
+
['sportdb-writers'],
|
25
|
+
## footballdata sources
|
26
|
+
['footballdata-api'],
|
27
|
+
['worldfootball'],
|
28
|
+
]
|
29
|
+
|
30
|
+
self.licenses = ['Public Domain']
|
31
|
+
|
32
|
+
self.spec_extras = {
|
33
|
+
required_ruby_version: '>= 2.2.2'
|
34
|
+
}
|
35
|
+
|
36
|
+
end
|
data/bin/fbgen
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
## tip: to test run:
|
4
|
+
## ruby -I ./lib bin/fbgen
|
5
|
+
|
6
|
+
require 'football/sources'
|
7
|
+
|
8
|
+
|
9
|
+
load_env ## use dotenv (.env)
|
10
|
+
|
11
|
+
|
12
|
+
Webcache.root = if File.exist?( '/sports/cache' )
|
13
|
+
puts " setting web cache to >/sports/cache<"
|
14
|
+
'/sports/cache'
|
15
|
+
else
|
16
|
+
'./cache'
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
## set openfootball github org root - note - NOT monorepo (github) root dirc
|
22
|
+
SportDb::GitHubSync.root = '/sports/openfootball'
|
23
|
+
|
24
|
+
|
25
|
+
## add convenience shortcuts
|
26
|
+
Country = Sports::Country
|
27
|
+
League = Sports::League
|
28
|
+
Club = Sports::Club
|
29
|
+
|
30
|
+
# Worldfootball.config.convert.out_dir = './o/aug29'
|
31
|
+
# Worldfootball.config.convert.out_dir = './o'
|
32
|
+
# Worldfootball.config.convert.out_dir = './o'
|
33
|
+
Worldfootball.config.convert.out_dir = if File.exist?( '/sports/cache.wfb' )
|
34
|
+
puts " setting wfb stage/cache to >/sports/cache.wfb<"
|
35
|
+
'/sports/cache.wfb'
|
36
|
+
else
|
37
|
+
'./stage/wfb'
|
38
|
+
end
|
39
|
+
#########
|
40
|
+
## staging cache settings
|
41
|
+
Footballdata.config.convert.out_dir = if File.exist?( '/sports/cache.api.fbdat' )
|
42
|
+
puts " setting fbdat stage/cache to >/sports/cache.api.fbdat<"
|
43
|
+
'/sports/cache.api.fbdat'
|
44
|
+
else
|
45
|
+
'./stage/fbdat'
|
46
|
+
end
|
47
|
+
|
48
|
+
pp File.expand_path( Footballdata.config.convert.out_dir )
|
49
|
+
|
50
|
+
|
51
|
+
## note - free tier (tier one) plan - 10 requests/minute
|
52
|
+
## (one request every 6 seconds 6*10=60 secs)
|
53
|
+
## 10 API calls per minute max.
|
54
|
+
## note - default sleep (delay in secs) is 3 sec(s)
|
55
|
+
Webget.config.sleep = 10
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
require 'optparse'
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
args=ARGV
|
65
|
+
|
66
|
+
|
67
|
+
opts = {
|
68
|
+
type: 'fbdat',
|
69
|
+
download: false,
|
70
|
+
push: false,
|
71
|
+
}
|
72
|
+
|
73
|
+
parser = OptionParser.new do |parser|
|
74
|
+
parser.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
75
|
+
|
76
|
+
# parser.on( "--cache", "--cached", "--offline",
|
77
|
+
# "use cached data in #{Webcache.root}" ) do |cached|
|
78
|
+
# opts[:cached] = cached
|
79
|
+
# end
|
80
|
+
|
81
|
+
parser.on( "-t NAME", "--type=NAME",
|
82
|
+
"use source type - default is (#{opts[:type]})" ) do |type|
|
83
|
+
opts[:type] = type
|
84
|
+
end
|
85
|
+
# end
|
86
|
+
|
87
|
+
|
88
|
+
# add download and push ???
|
89
|
+
|
90
|
+
end
|
91
|
+
parser.parse!( args )
|
92
|
+
|
93
|
+
puts "OPTS:"
|
94
|
+
p opts
|
95
|
+
puts "ARGV:"
|
96
|
+
p args
|
97
|
+
|
98
|
+
|
99
|
+
|
100
|
+
source = if ['fbdat'].include?( opts[:type] )
|
101
|
+
Footballdata
|
102
|
+
elsif ['wfb'].include?( opts[:type] )
|
103
|
+
Worldfootball
|
104
|
+
else
|
105
|
+
raise ArgumentError, "unknown source type - expected fbdata|wfb; got #{opts[:type]}"
|
106
|
+
end
|
107
|
+
|
108
|
+
puts "source:"
|
109
|
+
pp source
|
110
|
+
|
111
|
+
|
112
|
+
league = (args[0] || 'eng.1' ).downcase
|
113
|
+
season = (args[1] || '2024/25')
|
114
|
+
|
115
|
+
datasets = [
|
116
|
+
[league, [season]]
|
117
|
+
]
|
118
|
+
|
119
|
+
puts "datasets:"
|
120
|
+
pp datasets
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
Fbgen.process( datasets,
|
125
|
+
source: source,
|
126
|
+
download: opts[:download],
|
127
|
+
push: opts[:push] )
|
128
|
+
|
129
|
+
|
130
|
+
puts "bye"
|
131
|
+
|
data/lib/football/sources.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# note: allow require 'football/sources' too
|
2
|
-
# (in addition to require 'football-sources')
|
3
|
-
|
4
|
-
require_relative '../football-sources'
|
5
|
-
|
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,68 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module Fbgen
|
4
|
+
|
5
|
+
|
6
|
+
class Job ## todo/check: use a module (NOT a class) - why? why not?
|
7
|
+
## note - source expected module/class e.g. Footballdata/Worldfootball e.g.
|
8
|
+
def self.download( datasets, source: )
|
9
|
+
datasets.each_with_index do |dataset,i|
|
10
|
+
league = dataset[0]
|
11
|
+
seasons = dataset[1]
|
12
|
+
|
13
|
+
puts "downloading [#{i+1}/#{datasets.size}] #{league}..."
|
14
|
+
seasons.each_with_index do |season,j|
|
15
|
+
puts " season [#{j+1}/#{season.size}] #{league} #{season}..."
|
16
|
+
source.schedule( league: league,
|
17
|
+
season: season )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.convert( datasets, source: )
|
23
|
+
datasets.each_with_index do |dataset,i|
|
24
|
+
league = dataset[0]
|
25
|
+
seasons = dataset[1]
|
26
|
+
|
27
|
+
puts "converting [#{i+1}/#{datasets.size}] #{league}..."
|
28
|
+
seasons.each_with_index do |season,j|
|
29
|
+
puts " season [#{j+1}/#{season.size}] #{league} #{season}..."
|
30
|
+
source.convert( league: league,
|
31
|
+
season: season )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end # class Job
|
36
|
+
|
37
|
+
|
38
|
+
## change download? to cache - true/false - why? why not?
|
39
|
+
## change push: to sync - true/false - why? why not?
|
40
|
+
def self.process( datasets,
|
41
|
+
source:,
|
42
|
+
download: false,
|
43
|
+
push: false )
|
44
|
+
|
45
|
+
Job.download( datasets, source: source ) if download
|
46
|
+
|
47
|
+
## always pull before push!! (use fast_forward)
|
48
|
+
gh = SportDb::GitHubSync.new( datasets )
|
49
|
+
gh.git_fast_forward_if_clean if push
|
50
|
+
|
51
|
+
|
52
|
+
Job.convert( datasets, source: source )
|
53
|
+
|
54
|
+
if push
|
55
|
+
Writer.config.out_dir = SportDb::GitHubSync.root # e.g. "/sports/openfootball"
|
56
|
+
else
|
57
|
+
## fix/fix - use default - do not (re)set here - why? why not?
|
58
|
+
Writer.config.out_dir = './tmp'
|
59
|
+
end
|
60
|
+
|
61
|
+
Writer::Job.write( datasets,
|
62
|
+
source: source.config.convert.out_dir )
|
63
|
+
|
64
|
+
## todo/fix: add a getch or something to hit return before commiting pushing - why? why not?
|
65
|
+
gh.git_push_if_changes if push
|
66
|
+
end
|
67
|
+
|
68
|
+
end # module Fbgen
|
@@ -1,19 +1,19 @@
|
|
1
|
-
|
2
|
-
module FootballSources
|
3
|
-
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
4
|
-
MINOR =
|
5
|
-
PATCH = 0
|
6
|
-
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
7
|
-
|
8
|
-
def self.version
|
9
|
-
VERSION
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.banner
|
13
|
-
"football-sources/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.root
|
17
|
-
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
18
|
-
end
|
19
|
-
end # module FootballSources
|
1
|
+
|
2
|
+
module FootballSources
|
3
|
+
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
4
|
+
MINOR = 2
|
5
|
+
PATCH = 0
|
6
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
7
|
+
|
8
|
+
def self.version
|
9
|
+
VERSION
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.banner
|
13
|
+
"football-sources/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.root
|
17
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
18
|
+
end
|
19
|
+
end # module FootballSources
|
data/lib/football-sources.rb
CHANGED
@@ -1,57 +1,21 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
require 'sportdb/
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
%Q{"#{value}"}
|
23
|
-
else
|
24
|
-
value
|
25
|
-
end
|
26
|
-
end.join( ',' )
|
27
|
-
end
|
28
|
-
|
29
|
-
def self.write( path, recs, headers: )
|
30
|
-
## for convenience - make sure parent folders/directories exist
|
31
|
-
FileUtils.mkdir_p( File.dirname( path )) unless Dir.exist?( File.dirname( path ))
|
32
|
-
|
33
|
-
File.open( path, 'w:utf-8' ) do |f|
|
34
|
-
f.write( headers.join(',')) ## e.g. Date,Team 1,FT,HT,Team 2
|
35
|
-
f.write( "\n" )
|
36
|
-
recs.each do |values|
|
37
|
-
f.write( csv_encode( values ))
|
38
|
-
f.write( "\n" )
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end # class CsvMatchWriter
|
43
|
-
end # module Cache
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
###
|
49
|
-
# our own code
|
50
|
-
require 'football-sources/version' # let version always go first
|
51
|
-
|
52
|
-
require 'football-sources/apis'
|
53
|
-
require 'football-sources/worldfootball'
|
54
|
-
require 'football-sources/fbref'
|
55
|
-
|
56
|
-
|
57
|
-
puts FootballSources.banner # say hello
|
1
|
+
|
2
|
+
|
3
|
+
# require 'sportdb/formats' ## for Season etc.
|
4
|
+
require 'sportdb/catalogs' ## note: incl. deps csvreader etc.
|
5
|
+
require 'sportdb/writers'
|
6
|
+
|
7
|
+
|
8
|
+
require 'footballdata' # e.g. football-data.org (api)
|
9
|
+
require 'worldfootball' # e.g. weltfussball.de (web)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
###
|
14
|
+
# our own code
|
15
|
+
require_relative 'football-sources/version' # let version always go first
|
16
|
+
require_relative 'football-sources/process'
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
puts FootballSources.banner # say hello
|