football-to-psql 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +10 -0
- data/README.md +138 -0
- data/Rakefile +34 -0
- data/bin/football-to-psql +17 -0
- data/bin/football2psql +17 -0
- data/lib/football-to-psql.rb +124 -0
- data/lib/football-to-psql/version.rb +24 -0
- data/test/helper.rb +9 -0
- data/test/test_version.rb +17 -0
- metadata +109 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 79affa06d1e38ff1e8d4d7c91dce434b1046a104
|
4
|
+
data.tar.gz: 5183a62a72e7a11148017b538b42a8a63e48ecb4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d93a901601582e668cf5cf48304ba42f53d05a3709203654e832015636ac66627e0462a9fedbcc097c3e5ee03e6fd46730811517de79523e990e4be6180b96c2
|
7
|
+
data.tar.gz: 7c852682e58cb61aece7356a6a838cb7835e103a3b86a7f7f8c15b5bb534ff7cf8872802bf9579e4693238cd04e48f5d7c96d40732dadd694d27e1a21b58f077
|
data/CHANGELOG.md
ADDED
data/Manifest.txt
ADDED
data/README.md
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
# football-to-psql - load / read football.txt datafiles into a postgresql database
|
2
|
+
|
3
|
+
|
4
|
+
* home :: [github.com/sportdb/football.db](https://github.com/sportdb/football.db)
|
5
|
+
* bugs :: [github.com/sportdb/football.db/issues](https://github.com/sportdb/football.db/issues)
|
6
|
+
* gem :: [rubygems.org/gems/football-to-psql](https://rubygems.org/gems/football-to-psql)
|
7
|
+
* rdoc :: [rubydoc.info/gems/football-to-psql](http://rubydoc.info/gems/football-to-psql)
|
8
|
+
* forum :: [opensport](http://groups.google.com/group/opensport)
|
9
|
+
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
Try:
|
16
|
+
|
17
|
+
```
|
18
|
+
$ football-to-psql --help
|
19
|
+
```
|
20
|
+
|
21
|
+
printing:
|
22
|
+
|
23
|
+
|
24
|
+
```
|
25
|
+
Usage: football-to-psql [options] DATABASE PATHS...
|
26
|
+
-u, --username USERNAME database username (default: postgres)
|
27
|
+
-p, --password PASSWORD database password (default: postgres)
|
28
|
+
-h, --host HOST database host (default: localhost)
|
29
|
+
```
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
Run this tool against match files (for clubs or national teams) in the Football.TXT format like so:
|
35
|
+
|
36
|
+
```
|
37
|
+
$ football-to-psql england.db 2020-21/1-premierleague.txt
|
38
|
+
|
39
|
+
# -or-
|
40
|
+
|
41
|
+
$ football-to-psql worldcup.db 2018--russia/cup.txt
|
42
|
+
```
|
43
|
+
|
44
|
+
or pass in more than one match file (e.g. different leagues or more seasons / years ):
|
45
|
+
|
46
|
+
```
|
47
|
+
$ football-to-psql england.db 2020-21/1-premierleague.txt \
|
48
|
+
2020-21/2-championship.txt \
|
49
|
+
2020-21/3-league1.txt \
|
50
|
+
2020-21/4-league2.txt \
|
51
|
+
2020-21/5-nationalleague.txt
|
52
|
+
|
53
|
+
# -or-
|
54
|
+
|
55
|
+
$ football-to-psql premier.db 2020-21/1-premierleague.txt \
|
56
|
+
2019-20/1-premierleague.txt \
|
57
|
+
2018-19/1-premierleague.txt \
|
58
|
+
2017-18/1-premierleague.txt \
|
59
|
+
2016-17/1-premierleague.txt
|
60
|
+
|
61
|
+
# -or-
|
62
|
+
|
63
|
+
$ football-to-psql worldcup.db 2018--russia/cup.txt \
|
64
|
+
2018--russia/cup_finals.txt \
|
65
|
+
2014--brazil/cup.txt \
|
66
|
+
2014--brazil/cup_finals.txt \
|
67
|
+
2010--south-africa/cup.txt \
|
68
|
+
2010--south-africa/cup_finals.txt \
|
69
|
+
2006--germany/cup.txt \
|
70
|
+
2006--germany/cup_finals.txt \
|
71
|
+
2002--south-korea-n-japan/cup.txt \
|
72
|
+
2002--south-korea-n-japan/cup_finals.txt \
|
73
|
+
1998--france/cup.txt \
|
74
|
+
1998--france/cup_finals.txt \
|
75
|
+
1994--united-states/cup.txt \
|
76
|
+
1994--united-states/cup_finals.txt
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
Note: If the PostgreSQL database (and its tables, views & indices) do not (yet) exist, they get auto-created / auto-migrated on the first run.
|
81
|
+
|
82
|
+
|
83
|
+
Note: You can use `football2psql` as an alias / alternate name.
|
84
|
+
|
85
|
+
|
86
|
+
**Pipes & Standard Input (STDIN)**
|
87
|
+
|
88
|
+
You can use any command line tool to download match files and pipe (via stdin) into this tool like so:
|
89
|
+
|
90
|
+
```
|
91
|
+
$ curl https://raw.githubusercontent.com/openfootball/world-cup/master/2018--russia/cup.txt | football-to-psql worldcup.db
|
92
|
+
```
|
93
|
+
|
94
|
+
That's it for now.
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
## Limitations
|
100
|
+
|
101
|
+
Note: For now you CANNOT update match files, that is,
|
102
|
+
if you try to add the same match twice (assuming with updated scores or such), the match reader will fail for now.
|
103
|
+
The workaround is to always re-create/re-build your database from zero / scratch for now.
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
## Datasets
|
108
|
+
|
109
|
+
For some open public domain Football.TXT datasets to get started, see the [open football org](https://github.com/openfootball).
|
110
|
+
|
111
|
+
|
112
|
+
Add your datasets here!
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
## Installation
|
117
|
+
|
118
|
+
Use
|
119
|
+
|
120
|
+
gem install football-to-psql
|
121
|
+
|
122
|
+
or add the gem to your Gemfile
|
123
|
+
|
124
|
+
gem 'football-to-psql'
|
125
|
+
|
126
|
+
|
127
|
+
## License
|
128
|
+
|
129
|
+
The `football-to-psql` scripts are dedicated to the public domain.
|
130
|
+
Use it as you please with no restrictions whatsoever.
|
131
|
+
|
132
|
+
|
133
|
+
## Questions? Comments?
|
134
|
+
|
135
|
+
Send them along to the
|
136
|
+
[Open Sports & Friends Forum/Mailing List](http://groups.google.com/group/opensport).
|
137
|
+
Thanks!
|
138
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'hoe'
|
2
|
+
require './lib/football-to-psql/version.rb'
|
3
|
+
|
4
|
+
|
5
|
+
Hoe.spec 'football-to-psql' do
|
6
|
+
|
7
|
+
self.version = SportDb::Module::FootballToPsql::VERSION
|
8
|
+
|
9
|
+
self.summary = 'football-to-psql - load / read football.txt datafiles into a postgresql database'
|
10
|
+
self.description = summary
|
11
|
+
|
12
|
+
self.urls = { home: 'https://github.com/sportdb/football.db'}
|
13
|
+
|
14
|
+
self.author = 'Gerald Bauer'
|
15
|
+
self.email = 'opensport@googlegroups.com'
|
16
|
+
|
17
|
+
# switch extension to .markdown for gihub formatting
|
18
|
+
# -- Note: auto-changed when included in manifest
|
19
|
+
self.readme_file = 'README.md'
|
20
|
+
self.history_file = 'CHANGELOG.md'
|
21
|
+
|
22
|
+
self.extra_deps = [
|
23
|
+
['sportdb-readers', '>= 1.1.2'],
|
24
|
+
|
25
|
+
## ['activerecord'], # Note: will include activesupport,etc.
|
26
|
+
## ['postgres'],
|
27
|
+
]
|
28
|
+
|
29
|
+
self.licenses = ['Public Domain']
|
30
|
+
|
31
|
+
self.spec_extras = {
|
32
|
+
required_ruby_version: '>= 2.2.2'
|
33
|
+
}
|
34
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
###################
|
4
|
+
# == DEV TIPS:
|
5
|
+
#
|
6
|
+
# For local testing run like:
|
7
|
+
#
|
8
|
+
# ruby -Ilib bin/football-to-psql
|
9
|
+
#
|
10
|
+
# Set the executable bit in Linux. Example:
|
11
|
+
#
|
12
|
+
# % chmod a+x bin/football-to-psql
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'football-to-psql'
|
16
|
+
|
17
|
+
FootballToPsql.main
|
data/bin/football2psql
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
###################
|
4
|
+
# == DEV TIPS:
|
5
|
+
#
|
6
|
+
# For local testing run like:
|
7
|
+
#
|
8
|
+
# ruby -Ilib bin/football2psql
|
9
|
+
#
|
10
|
+
# Set the executable bit in Linux. Example:
|
11
|
+
#
|
12
|
+
# % chmod a+x bin/football2psql
|
13
|
+
#
|
14
|
+
|
15
|
+
require 'football-to-psql'
|
16
|
+
|
17
|
+
FootballToPsql.main
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
require 'sportdb/readers'
|
4
|
+
|
5
|
+
require 'logutils/activerecord' ## NOTE: check - add to/include in/move to sportdb/models
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
###
|
10
|
+
# our own code
|
11
|
+
require 'football-to-psql/version' # let version always go first
|
12
|
+
|
13
|
+
|
14
|
+
module FootballToPsql
|
15
|
+
class Tool
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
LogUtils::Logger.root.level = :info # set logging level to info
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def connect( dbconfig )
|
24
|
+
puts "working directory: #{Dir.pwd}"
|
25
|
+
|
26
|
+
SportDb.connect( dbconfig )
|
27
|
+
|
28
|
+
SportDb.auto_migrate!
|
29
|
+
|
30
|
+
LogDb.setup # start logging to db (that is, save logs in logs table in db)
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
def run( args )
|
36
|
+
dbconfig = {
|
37
|
+
adapter: 'postgresql',
|
38
|
+
encoding: 'unicode',
|
39
|
+
username: 'postgres',
|
40
|
+
password: 'postgres',
|
41
|
+
host: 'localhost',
|
42
|
+
database: 'sport.db',
|
43
|
+
pool: 5,
|
44
|
+
timeout: 5000
|
45
|
+
}
|
46
|
+
|
47
|
+
options = {}
|
48
|
+
optparser = OptionParser.new do |parser|
|
49
|
+
parser.banner = "Usage: football-to-psql [options] DATABASE PATHS..."
|
50
|
+
|
51
|
+
parser.on( '-u', '--user USERNAME', '--username USERNAME',
|
52
|
+
"database username (default: #{dbconfig[:username]})" ) do |username|
|
53
|
+
options[:username] = username
|
54
|
+
end
|
55
|
+
|
56
|
+
parser.on( '-p', '--password PASSWORD',
|
57
|
+
"database password (default: #{dbconfig[:password]})" ) do |password|
|
58
|
+
options[:password] = password
|
59
|
+
end
|
60
|
+
|
61
|
+
parser.on( '-h', '--host HOST',
|
62
|
+
"database host (default: #{dbconfig[:host]})" ) do |host|
|
63
|
+
options[:host] = host
|
64
|
+
end
|
65
|
+
end
|
66
|
+
optparser.parse!( args )
|
67
|
+
|
68
|
+
if args.empty?
|
69
|
+
puts "!! ERROR - postgresql database name expected (e.g. sport.db)"
|
70
|
+
puts optparser.help
|
71
|
+
exit 1
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
dbname = args.shift
|
77
|
+
puts "dbname: >#{dbname}<"
|
78
|
+
puts "args:"
|
79
|
+
p args
|
80
|
+
|
81
|
+
dbconfig[:database] = dbname
|
82
|
+
|
83
|
+
dbconfig[:username] = options[:username] if options[:username]
|
84
|
+
dbconfig[:password] = options[:password] if options[:password]
|
85
|
+
dbconfig[:host] = options[:host] if options[:host]
|
86
|
+
|
87
|
+
|
88
|
+
connect( dbconfig )
|
89
|
+
|
90
|
+
args.each do |arg|
|
91
|
+
puts "reading #{arg}..."
|
92
|
+
## note: only support reading matchfiles for now (NOT zips & dirs or clubs & leagues etc.)
|
93
|
+
SportDb.read_match( arg )
|
94
|
+
end
|
95
|
+
|
96
|
+
## todo: check if stdin is always utf-8 or such?
|
97
|
+
unless STDIN.tty?
|
98
|
+
puts "reading STDIN..."
|
99
|
+
## assume/ read stdin as utf8 - possible?
|
100
|
+
txt = STDIN.read
|
101
|
+
puts "[------------->>>"
|
102
|
+
puts txt
|
103
|
+
puts "<<<-------------]"
|
104
|
+
SportDb.parse_match( txt )
|
105
|
+
puts "encoding: #{txt.encoding}"
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
## print some stats
|
110
|
+
SportDb.tables
|
111
|
+
|
112
|
+
puts "Done."
|
113
|
+
end # method run
|
114
|
+
|
115
|
+
|
116
|
+
end # class Tool
|
117
|
+
|
118
|
+
|
119
|
+
def self.main( args=ARGV ) Tool.new.run( args ); end
|
120
|
+
end # module FootballToPsql
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
puts SportDb::Module::FootballToPsql.banner # say hello
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module SportDb
|
2
|
+
module Module
|
3
|
+
module FootballToPsql
|
4
|
+
|
5
|
+
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
6
|
+
MINOR = 1
|
7
|
+
PATCH = 0
|
8
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
|
+
|
10
|
+
def self.version
|
11
|
+
VERSION
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.banner
|
15
|
+
"football-to-psql/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.root
|
19
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
20
|
+
end
|
21
|
+
|
22
|
+
end # module FootballToPsql
|
23
|
+
end # module Module
|
24
|
+
end # module SportDb
|
data/test/helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
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
|
+
puts SportDb::Module::FootballToPsql.banner
|
12
|
+
puts SportDb::Module::FootballToPsql.root
|
13
|
+
puts SportDb::Module::FootballToPsql::VERSION
|
14
|
+
end
|
15
|
+
|
16
|
+
end # class TestVersion
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: football-to-psql
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sportdb-readers
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.1.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.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rdoc
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '7'
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '4.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: hoe
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.22'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.22'
|
61
|
+
description: football-to-psql - load / read football.txt datafiles into a postgresql
|
62
|
+
database
|
63
|
+
email: opensport@googlegroups.com
|
64
|
+
executables:
|
65
|
+
- football-to-psql
|
66
|
+
- football2psql
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files:
|
69
|
+
- CHANGELOG.md
|
70
|
+
- Manifest.txt
|
71
|
+
- README.md
|
72
|
+
files:
|
73
|
+
- CHANGELOG.md
|
74
|
+
- Manifest.txt
|
75
|
+
- README.md
|
76
|
+
- Rakefile
|
77
|
+
- bin/football-to-psql
|
78
|
+
- bin/football2psql
|
79
|
+
- lib/football-to-psql.rb
|
80
|
+
- lib/football-to-psql/version.rb
|
81
|
+
- test/helper.rb
|
82
|
+
- test/test_version.rb
|
83
|
+
homepage: https://github.com/sportdb/football.db
|
84
|
+
licenses:
|
85
|
+
- Public Domain
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options:
|
89
|
+
- "--main"
|
90
|
+
- README.md
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.2.2
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.5.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: football-to-psql - load / read football.txt datafiles into a postgresql database
|
109
|
+
test_files: []
|