football-cat 0.1.0 → 0.1.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 +1 -0
- data/lib/football-cat/tool.rb +115 -0
- data/lib/football-cat/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5ec4bf16056fff1c0b767ad696d563852a5e107
|
4
|
+
data.tar.gz: 809bf72089bef2491ddefea64d247e01b468aa2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08b0fb02547bea1de411aa9efb0d55c28d6aef6d980b427703cbb99d7ab92a1f316bd0a228bc10bc8c9abdd210f6936cd816ddaf94cd16bcd00de0ca9acc646e'
|
7
|
+
data.tar.gz: 3fdd83eb41a43efef8b722a617f56f9074a3f53d8410c8b5d481335c44f0263fecdcb9fa27e4071ef1984964eb757869a2ef256ac8ca5e29aeb26d6a25bf7c43
|
data/Manifest.txt
CHANGED
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
module FootballCat
|
3
|
+
class Tool
|
4
|
+
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
end
|
8
|
+
|
9
|
+
|
10
|
+
def run( args )
|
11
|
+
|
12
|
+
options = {}
|
13
|
+
optparser = OptionParser.new do |parser|
|
14
|
+
parser.banner = "Usage: football-cat [options] OUTPATH INPATHS..."
|
15
|
+
end
|
16
|
+
optparser.parse!( args )
|
17
|
+
|
18
|
+
if args.empty?
|
19
|
+
puts "!! ERROR - football.csv name/path expected (e.g. league.csv)"
|
20
|
+
puts optparser.help
|
21
|
+
exit 1
|
22
|
+
end
|
23
|
+
|
24
|
+
outpath = args.shift
|
25
|
+
puts "outpath: >#{outpath}<"
|
26
|
+
puts "args:"
|
27
|
+
p args
|
28
|
+
|
29
|
+
headers = nil
|
30
|
+
|
31
|
+
args.each do |arg|
|
32
|
+
inpath = File.expand_path( arg )
|
33
|
+
puts "reading #{inpath}..."
|
34
|
+
|
35
|
+
if File.directory?( inpath )
|
36
|
+
pack = SportDb::DirPackage.new( inpath )
|
37
|
+
pack.each_csv do |entry|
|
38
|
+
puts " #{entry.name}"
|
39
|
+
|
40
|
+
basename = File.basename( entry.name, File.extname( entry.name ) ) ## get basename WITHOUT extension
|
41
|
+
|
42
|
+
## note: upcase for now and remove dots e.g.
|
43
|
+
## es.1 => ES1
|
44
|
+
## de.cup => DECUP - why? why not?
|
45
|
+
league_key = basename.upcase.gsub( '.', '' )
|
46
|
+
|
47
|
+
## todo/fix: check if season_key is proper season - e.g. matches pattern !!!!
|
48
|
+
season_q = File.basename( File.dirname( entry.name ))
|
49
|
+
season = Season.parse( season_q ) ## normalize season
|
50
|
+
season_key = season.key
|
51
|
+
|
52
|
+
puts " league: #{league_key}, season: #{season_key}"
|
53
|
+
|
54
|
+
txt = entry.read
|
55
|
+
## matches = SportDb::CsvMatchParser.parse( txt )
|
56
|
+
rows = CsvHash.parse( txt )
|
57
|
+
puts " addinging #{rows.size} match(es)..."
|
58
|
+
# rows = rows.map do |row|
|
59
|
+
# { 'League' => league_key,
|
60
|
+
# 'Season' => season_key }.merge( row )
|
61
|
+
# end
|
62
|
+
# pp rows[0..2]
|
63
|
+
|
64
|
+
if headers.nil?
|
65
|
+
## first time - create file with headers
|
66
|
+
headers = ['League', 'Season'] + rows[0].keys
|
67
|
+
puts "headers:"
|
68
|
+
pp headers
|
69
|
+
|
70
|
+
FileUtils.mkdir_p( File.dirname( outpath )) ## make sure path exists
|
71
|
+
File.open( outpath, 'w:utf-8' ) do |f|
|
72
|
+
f.write( headers.join(',') )
|
73
|
+
f.write( "\n" )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
File.open( outpath, 'a:utf-8' ) do |f|
|
78
|
+
rows.each do |row|
|
79
|
+
f.write( csv_encode( [ league_key, season_key ] + row.values ))
|
80
|
+
f.write( "\n")
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
else ## assume "free-standing" single datatfile
|
85
|
+
puts "!! WARN - skipping datafile >#{inpath}< - sorry - for now only directories / packages work"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
puts "Done."
|
91
|
+
end # method run
|
92
|
+
|
93
|
+
##########
|
94
|
+
# helpers
|
95
|
+
def csv_encode( values )
|
96
|
+
## quote values that incl. a comma
|
97
|
+
values.map do |value|
|
98
|
+
if value.index(',')
|
99
|
+
puts "** rec with field with comma:"
|
100
|
+
pp values
|
101
|
+
%Q{"#{value}"}
|
102
|
+
else
|
103
|
+
value
|
104
|
+
end
|
105
|
+
end.join( ',' )
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
end # class Tool
|
110
|
+
|
111
|
+
|
112
|
+
def self.main( args=ARGV )
|
113
|
+
Tool.new.run( args )
|
114
|
+
end
|
115
|
+
end # module FootballCat
|
data/lib/football-cat/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: football-cat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- Rakefile
|
76
76
|
- bin/football-cat
|
77
77
|
- lib/football-cat.rb
|
78
|
+
- lib/football-cat/tool.rb
|
78
79
|
- lib/football-cat/version.rb
|
79
80
|
- test/helper.rb
|
80
81
|
- test/test_version.rb
|