sportdb 2.1.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +2 -0
- data/Rakefile +6 -9
- data/lib/sportdb.rb +67 -12
- data/lib/sportdb/cli/main.rb +66 -32
- data/lib/sportdb/cli/opts.rb +17 -8
- data/lib/sportdb/cli/version.rb +2 -2
- data/test/helper.rb +9 -0
- data/test/test_commands.rb +17 -0
- metadata +11 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0abc35fb1d3dbb732804349eeec3c26a6dc63d99
|
4
|
+
data.tar.gz: 6e7338d3c6d9b8765e42dcbbac64b418d1761d6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 458d9011e99e6abbe78ae1d9448f9175c2057a4cf7869ce66f50aeb8572157ff64721f21d318ddcee64d6917bf5dfeac4ec045b50d4e5ec95fb0abe74aebcefb
|
7
|
+
data.tar.gz: edfbbb41911d7ad3687381a8d5471ce3c7f289cdf03ed95ea7098519253b3c3ee0b493c920874165a601df272d60f9ae3ff57dc89dce8bf5cbb5474ed64b3c56
|
data/Manifest.txt
CHANGED
data/Rakefile
CHANGED
@@ -20,21 +20,18 @@ Hoe.spec 'sportdb' do
|
|
20
20
|
self.history_file = 'CHANGELOG.md'
|
21
21
|
|
22
22
|
self.extra_deps = [
|
23
|
-
['sportdb-
|
24
|
-
['sportdb-readers', '>= 0.3.6'],
|
25
|
-
['footballdb-leagues', '>= 2019.11.22' ], ## add minimum for datasets
|
26
|
-
['footballdb-clubs', '>= 2019.11.22' ],
|
23
|
+
['sportdb-readers', '>= 1.1.2'],
|
27
24
|
|
28
|
-
['fetcher',
|
29
|
-
['datafile',
|
25
|
+
['fetcher', '>= 0.4.5'], ## check if included already in datafil ??
|
26
|
+
['datafile', '>= 0.3.1'],
|
27
|
+
['webservice', '>= 0.7.0'],
|
30
28
|
|
31
|
-
### sportdb addons
|
29
|
+
### incl. sportdb addons - why? why not?
|
32
30
|
## ['sportdb-keys'],
|
33
31
|
## ['sportdb-update'],
|
34
|
-
['sportdb-service'],
|
35
32
|
|
36
33
|
## 3rd party
|
37
|
-
['gli', '>= 2.
|
34
|
+
['gli', '>= 2.19.0'],
|
38
35
|
|
39
36
|
## ['activerecord'], # Note: will include activesupport,etc.
|
40
37
|
['sqlite3']
|
data/lib/sportdb.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
require 'sportdb/models'
|
5
3
|
require 'sportdb/readers'
|
6
4
|
|
7
5
|
require 'logutils/activerecord' ## NOTE: check - add to/include in/move to sportdb/models
|
@@ -19,24 +17,81 @@ require 'sportdb/cli/opts'
|
|
19
17
|
require 'sportdb/cli/main'
|
20
18
|
|
21
19
|
|
20
|
+
|
22
21
|
module SportDb
|
23
22
|
|
24
|
-
def self.main
|
25
|
-
Tool.new.run(
|
23
|
+
def self.main( args=ARGV )
|
24
|
+
Tool.new.run( args )
|
26
25
|
end
|
27
26
|
|
28
27
|
end # module SportDb
|
29
28
|
|
30
29
|
|
31
|
-
#####
|
32
|
-
# auto-load/require some addons
|
33
30
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
31
|
+
##################
|
32
|
+
# add web service support / machinery
|
33
|
+
|
34
|
+
require 'webservice'
|
35
|
+
|
36
|
+
####
|
37
|
+
## used for server/service command
|
38
|
+
## "preconfigured" base class for webservice
|
39
|
+
class SportDbService < Webservice::Base
|
40
|
+
include SportDb::Models # e.g. League, Season, Team, etc.
|
41
|
+
|
42
|
+
## (auto-)add some (built-in) routes
|
43
|
+
|
44
|
+
get '/version(s)?' do
|
45
|
+
{
|
46
|
+
"sportdb": SportDbCli::VERSION, ## todo/fix: change to DbTool!!!
|
47
|
+
"sportdb/models": SportDb::VERSION,
|
48
|
+
## todo/fix: add beerdb/note version - if present
|
49
|
+
## todo/fix: add worlddb/models version
|
50
|
+
## todo/fix: add some more libs - why? why not??
|
51
|
+
"activerecord": [ActiveRecord::VERSION::MAJOR,ActiveRecord::VERSION::MINOR,ActiveRecord::VERSION::TINY].join('.'),
|
52
|
+
"webservice": Webservice::VERSION,
|
53
|
+
"rack": "#{Rack::RELEASE} (#{Rack::VERSION.join('.')})", ## note: VERSION is the protocoll version as an array e.g.[1,2]
|
54
|
+
"ruby": "#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]",
|
55
|
+
}
|
56
|
+
end
|
57
|
+
|
58
|
+
get '/(stats|tables)' do
|
59
|
+
{
|
60
|
+
"teams": SportDb::Model::Team.count,
|
61
|
+
"games": SportDb::Model::Game.count,
|
62
|
+
"events": SportDb::Model::Event.count,
|
63
|
+
"leagues": SportDb::Model::League.count,
|
64
|
+
"seasons": SportDb::Model::Season.count,
|
65
|
+
"countries": WorldDb::Model::Country.count,
|
66
|
+
"system": {
|
67
|
+
"props": ConfDb::Models::Prop.count,
|
68
|
+
"logs": LogDb::Models::Log.count,
|
69
|
+
}
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
get '/props(.:format)?' do # note: add format - lets you use props.csv and props.html
|
74
|
+
ConfDb::Models::Prop.all
|
75
|
+
end
|
76
|
+
|
77
|
+
get '/logs(.:format)?' do
|
78
|
+
LogDb::Models::Log.all
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
## add favicon support
|
83
|
+
# get '/favicon.ico' do
|
84
|
+
## use 302 to redirect
|
85
|
+
## note: use strg+F5 to refresh page (clear cache for favicon.ico)
|
86
|
+
# redirect '/webservice-sportdb-32x32.png'
|
87
|
+
# end
|
88
|
+
|
89
|
+
# get '/webservice-beerdb-32x32.png' do
|
90
|
+
# send_file "#{SportDbCli.root}/assets/webservice-sportdb-32x32.png"
|
91
|
+
# end
|
92
|
+
|
93
|
+
end # class SportDbService
|
94
|
+
|
40
95
|
|
41
96
|
|
42
97
|
SportDb.main if __FILE__ == $0
|
data/lib/sportdb/cli/main.rb
CHANGED
@@ -60,6 +60,23 @@ arg_name 'NAME'
|
|
60
60
|
default_value opts.db_name
|
61
61
|
flag [:n, :dbname]
|
62
62
|
|
63
|
+
desc 'Datafile'
|
64
|
+
arg_name 'FILE'
|
65
|
+
default_value opts.datafile
|
66
|
+
flag [:f, :datafile]
|
67
|
+
|
68
|
+
desc 'Leagues dir'
|
69
|
+
arg_name 'PATH'
|
70
|
+
default_value nil
|
71
|
+
flag [:'leagues-dir', :leaguesdir]
|
72
|
+
|
73
|
+
desc 'Clubs dir'
|
74
|
+
arg_name 'PATH'
|
75
|
+
default_value nil
|
76
|
+
flag [:'clubs-dir', :clubsdir]
|
77
|
+
|
78
|
+
|
79
|
+
|
63
80
|
desc '(Debug) Show debug messages'
|
64
81
|
switch [:verbose], negatable: false ## todo: use -w for short form? check ruby interpreter if in use too?
|
65
82
|
|
@@ -87,8 +104,8 @@ command [:build,:b] do |c|
|
|
87
104
|
c.action do |g,o,args|
|
88
105
|
|
89
106
|
## check if datafile exists, if NOT assume working dir (./) is a package
|
90
|
-
if File.file?(
|
91
|
-
datafile = Datafile::Datafile.load_file(
|
107
|
+
if File.file?( opts.datafile ) ## note use file? (exist? will also check for directory/folder!!)
|
108
|
+
datafile = Datafile::Datafile.load_file( opts.datafile )
|
92
109
|
datafile.download # datafile step 1 - download all datasets/zips
|
93
110
|
|
94
111
|
connect_to_db( opts )
|
@@ -97,7 +114,7 @@ command [:build,:b] do |c|
|
|
97
114
|
|
98
115
|
datafile.read # datafile step 2 - read all datasets
|
99
116
|
else
|
100
|
-
puts "no
|
117
|
+
puts "no datafile >#{opts.datafile}< found; trying local build in >#{Dir.pwd}<"
|
101
118
|
|
102
119
|
connect_to_db( opts )
|
103
120
|
|
@@ -117,13 +134,13 @@ command [:read,:r] do |c|
|
|
117
134
|
c.action do |g,o,args|
|
118
135
|
|
119
136
|
## check if datafile exists, if NOT assume working dir (./) is a package
|
120
|
-
if File.file?(
|
137
|
+
if File.file?( opts.datafile ) ## note use file? (exist? will also check for directory/folder!!)
|
121
138
|
connect_to_db( opts )
|
122
139
|
|
123
|
-
datafile = Datafile::Datafile.load_file(
|
140
|
+
datafile = Datafile::Datafile.load_file( opts.datafile )
|
124
141
|
datafile.read
|
125
142
|
else
|
126
|
-
puts "no
|
143
|
+
puts "no datafile >#{opts.datafile}< found; trying local read in >#{Dir.pwd}<"
|
127
144
|
|
128
145
|
connect_to_db( opts )
|
129
146
|
|
@@ -143,7 +160,7 @@ command [:download,:dl] do |c|
|
|
143
160
|
|
144
161
|
# note: no database connection needed (check - needed for logs?? - not setup by default???)
|
145
162
|
|
146
|
-
datafile = Datafile::Datafile.load_file(
|
163
|
+
datafile = Datafile::Datafile.load_file( opts.datafile )
|
147
164
|
datafile.download
|
148
165
|
|
149
166
|
puts 'Done.'
|
@@ -163,6 +180,8 @@ command [:new,:n] do |c|
|
|
163
180
|
worker = Fetcher::Worker.new
|
164
181
|
worker.copy( "https://github.com/openfootball/datafile/raw/master/#{setup}.rb", './Datafile' )
|
165
182
|
|
183
|
+
## todo/check: use custom datafile (opts.datafile) if present? why? why not?
|
184
|
+
|
166
185
|
## step 2: same as command build (todo - reuse code)
|
167
186
|
datafile = Datafile::Datafile.load_file( './Datafile' )
|
168
187
|
datafile.download # datafile step 1 - download all datasets/zips
|
@@ -178,38 +197,40 @@ command [:new,:n] do |c|
|
|
178
197
|
end # command setup
|
179
198
|
|
180
199
|
|
181
|
-
|
182
200
|
desc 'Start web service (HTTP JSON API)'
|
183
|
-
|
201
|
+
arg_name 'NAME' # optional setup profile name
|
202
|
+
command [:serve,:server,:s] do |c|
|
184
203
|
|
185
204
|
c.action do |g,o,args|
|
186
205
|
|
187
|
-
|
206
|
+
## todo: document optional script arg (defaults to service)
|
207
|
+
script = args[0] || 'service'
|
208
|
+
|
209
|
+
## todo/fix: add support for (default) Service (with no extension)
|
210
|
+
|
211
|
+
script_path = "#{script}.rb" ## auto-add .rb extension
|
188
212
|
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
#
|
195
|
-
# after do
|
196
|
-
# ActiveRecord::Base.connection.close
|
197
|
-
# end
|
198
|
-
#
|
199
|
-
|
200
|
-
puts 'before add middleware ConnectionManagement'
|
201
|
-
SportDb::Service::Server.use ActiveRecord::ConnectionAdapters::ConnectionManagement
|
202
|
-
puts 'after add middleware ConnectionManagement'
|
203
|
-
## todo: check if we can check on/dump middleware stack
|
204
|
-
|
205
|
-
## rack middleware might not work with multi-threaded thin web server; close it ourselfs
|
206
|
-
SportDb::Service::Server.after do
|
207
|
-
puts " #{Thread.current.object_id} -- make sure db connections gets closed after request"
|
208
|
-
# todo: check if connection is open - how?
|
209
|
-
ActiveRecord::Base.connection.close
|
213
|
+
unless File.exist?( script_path ) ## if file doesn't exist try to fetch service script
|
214
|
+
script_path = "./#{script}.rb" ## use / save script in local (current) working dir/folder
|
215
|
+
worker = Fetcher::Worker.new
|
216
|
+
## note: lets use http:// instead of https:// for now - lets us use person proxy (NOT working w/ https for now)
|
217
|
+
worker.copy( "http://github.com/sportdb/sport.db.service/raw/master/#{script}.rb", script_path )
|
210
218
|
end
|
211
219
|
|
212
|
-
|
220
|
+
|
221
|
+
code = File.open( script_path, 'r:utf-8' ) { |f| f.read }
|
222
|
+
|
223
|
+
connect_to_db( opts )
|
224
|
+
|
225
|
+
SportDb.tables ## print table stats
|
226
|
+
|
227
|
+
SportDbService.class_eval( code ) ## note: MUST use class_eval (do NOT use instance_eval) !!!
|
228
|
+
|
229
|
+
puts "dump routes:"
|
230
|
+
pp SportDbService.routes
|
231
|
+
|
232
|
+
puts "starting server..."
|
233
|
+
SportDbService.run!
|
213
234
|
|
214
235
|
puts 'Done.'
|
215
236
|
end
|
@@ -217,6 +238,7 @@ end # command serve
|
|
217
238
|
|
218
239
|
|
219
240
|
|
241
|
+
|
220
242
|
desc 'Show logs'
|
221
243
|
command :logs do |c|
|
222
244
|
c.action do |g,o,args|
|
@@ -293,6 +315,18 @@ pre do |g,c,o,args|
|
|
293
315
|
LogUtils::Logger.root.level = :debug
|
294
316
|
end
|
295
317
|
|
318
|
+
|
319
|
+
if opts.clubs_dir?
|
320
|
+
puts " setting clubs_dir to >#{opts.clubs_dir}<"
|
321
|
+
SportDb::Import.config.clubs_dir = opts.clubs_dir
|
322
|
+
end
|
323
|
+
|
324
|
+
if opts.leagues_dir?
|
325
|
+
puts " setting leagues_dir to >#{opts.leagues_dir}<"
|
326
|
+
SportDb::Import.config.leagues_dir = opts.leagues_dir
|
327
|
+
end
|
328
|
+
|
329
|
+
|
296
330
|
logger.debug "Executing #{c.name}"
|
297
331
|
true
|
298
332
|
end
|
data/lib/sportdb/cli/opts.rb
CHANGED
@@ -5,10 +5,14 @@ module SportDb
|
|
5
5
|
class Opts
|
6
6
|
|
7
7
|
def merge_gli_options!( options = {} )
|
8
|
-
@db_path = options[:dbpath]
|
9
|
-
@db_name = options[:dbname]
|
8
|
+
@db_path = options[:dbpath] if options[:dbpath].present?
|
9
|
+
@db_name = options[:dbname] if options[:dbname].present?
|
10
|
+
@datafile = options[:datafile] if options[:datafile].present?
|
10
11
|
|
11
12
|
@verbose = true if options[:verbose] == true
|
13
|
+
|
14
|
+
@leagues_dir = options[:'leagues-dir'] if options[:'leagues-dir'].present?
|
15
|
+
@clubs_dir = options[:'clubs-dir'] if options[:'clubs-dir'].present?
|
12
16
|
end
|
13
17
|
|
14
18
|
|
@@ -22,13 +26,18 @@ class Opts
|
|
22
26
|
end
|
23
27
|
|
24
28
|
|
25
|
-
def db_path
|
26
|
-
|
27
|
-
end
|
29
|
+
def db_path() @db_path || '.'; end
|
30
|
+
def db_name() @db_name || 'sport.db'; end
|
28
31
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
+
def datafile() @datafile || './Datafile'; end
|
33
|
+
def datafile?() @datafile; end ## note: let's you check if datafile is set (or "untouched")
|
34
|
+
|
35
|
+
|
36
|
+
def clubs_dir() @clubs_dir; end
|
37
|
+
def clubs_dir?() @clubs_dir.nil? == false; end ## note: let's you check if clubs_dir set (by default it's NOT set)
|
38
|
+
|
39
|
+
def leagues_dir() @leagues_dir; end
|
40
|
+
def leagues_dir?() @leagues_dir.nil? == false; end
|
32
41
|
end # class Opts
|
33
42
|
|
34
43
|
end # module SportDb
|
data/lib/sportdb/cli/version.rb
CHANGED
@@ -6,8 +6,8 @@
|
|
6
6
|
module SportDbCli # todo/check - rename to SportDbTool or SportDbCommands or SportDbShell ??
|
7
7
|
|
8
8
|
MAJOR = 2 ## todo: namespace inside version or something - why? why not??
|
9
|
-
MINOR =
|
10
|
-
PATCH =
|
9
|
+
MINOR = 3
|
10
|
+
PATCH = 1
|
11
11
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
12
12
|
|
13
13
|
def self.version
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_commands.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestCommands < MiniTest::Test
|
11
|
+
|
12
|
+
def test_help
|
13
|
+
args = ['help']
|
14
|
+
SportDb.main( args )
|
15
|
+
end
|
16
|
+
|
17
|
+
end # class TestCommands
|
metadata
CHANGED
@@ -1,71 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: sportdb-models
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: 1.18.2
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: 1.18.2
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: sportdb-readers
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
30
16
|
requirements:
|
31
17
|
- - ">="
|
32
18
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
19
|
+
version: 1.1.2
|
34
20
|
type: :runtime
|
35
21
|
prerelease: false
|
36
22
|
version_requirements: !ruby/object:Gem::Requirement
|
37
23
|
requirements:
|
38
24
|
- - ">="
|
39
25
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: footballdb-leagues
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 2019.11.22
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2019.11.22
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: footballdb-clubs
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 2019.11.22
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 2019.11.22
|
26
|
+
version: 1.1.2
|
69
27
|
- !ruby/object:Gem::Dependency
|
70
28
|
name: fetcher
|
71
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,33 +53,33 @@ dependencies:
|
|
95
53
|
- !ruby/object:Gem::Version
|
96
54
|
version: 0.3.1
|
97
55
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
56
|
+
name: webservice
|
99
57
|
requirement: !ruby/object:Gem::Requirement
|
100
58
|
requirements:
|
101
59
|
- - ">="
|
102
60
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
61
|
+
version: 0.7.0
|
104
62
|
type: :runtime
|
105
63
|
prerelease: false
|
106
64
|
version_requirements: !ruby/object:Gem::Requirement
|
107
65
|
requirements:
|
108
66
|
- - ">="
|
109
67
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
68
|
+
version: 0.7.0
|
111
69
|
- !ruby/object:Gem::Dependency
|
112
70
|
name: gli
|
113
71
|
requirement: !ruby/object:Gem::Requirement
|
114
72
|
requirements:
|
115
73
|
- - ">="
|
116
74
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.
|
75
|
+
version: 2.19.0
|
118
76
|
type: :runtime
|
119
77
|
prerelease: false
|
120
78
|
version_requirements: !ruby/object:Gem::Requirement
|
121
79
|
requirements:
|
122
80
|
- - ">="
|
123
81
|
- !ruby/object:Gem::Version
|
124
|
-
version: 2.
|
82
|
+
version: 2.19.0
|
125
83
|
- !ruby/object:Gem::Dependency
|
126
84
|
name: sqlite3
|
127
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,6 +142,8 @@ files:
|
|
184
142
|
- lib/sportdb/cli/opts.rb
|
185
143
|
- lib/sportdb/cli/version.rb
|
186
144
|
- lib/sportdb/console.rb
|
145
|
+
- test/helper.rb
|
146
|
+
- test/test_commands.rb
|
187
147
|
homepage: https://github.com/sportdb/sport.db
|
188
148
|
licenses:
|
189
149
|
- Public Domain
|