fbtxt2json 0.0.1 → 0.2.0

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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -0
  3. data/README.md +61 -1
  4. data/Rakefile +6 -5
  5. data/bin/fbtxt2json +107 -31
  6. metadata +22 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8956db527655b3b148c5e0ee4d456cbb26ce6444d382ae65c9a651c6e3c29a1b
4
- data.tar.gz: 695ffa9fff51b0f0e0e0751d7a3366344ccf13a2524abe87a10264a3c6087ffd
3
+ metadata.gz: 1110851daf4ad4e65784b4287e164d916a64dd6604fbe8c40c5f930c93deb19b
4
+ data.tar.gz: 98581c266f12caa2845bdc88456b99881ff947a77d29eb2cef5ff6c70bfca799
5
5
  SHA512:
6
- metadata.gz: 54a88a9c80c4113334ae6c6a4ba1381349bcb6b17ded024381fdc95bd9706e71a8ab4e87e586f2e0e8610a8c5db7db0d9fbcca232fcb65e6343cd3ec166c5bba
7
- data.tar.gz: 1d890a6514ab755a99f188c67974fc160f55a8e34ef946e926186754a0d0dd4110ce359920a1aadebfd0f50b7e9a50419acba7952af4323c796d490739ac590b
6
+ metadata.gz: 0c6ff84e6043ac1eefe34cd8eed96ccc8249f93c7d668c1263bdcdb54001f5e9149412aeca9d9bc428d734f56f18bca17f89339084deb7034b2b7418c30523ef
7
+ data.tar.gz: 6e0f34b49d0f3abf9a0d9cf1dedfb045a9f2a88163791d0175cae05fe706d4cc6ac2a6e97e7dc7bf80ae60e6a94901406e2ed4059808b1eca66edee8e3429589
data/CHANGELOG.md CHANGED
@@ -1,3 +1,4 @@
1
+ ### 0.2.0
1
2
  ### 0.0.1 / 2024-09-28
2
3
 
3
4
  * Everything is new. First release.
data/README.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # fbtxt2json - convert football.txt match schedules & more to json
2
2
 
3
3
 
4
+ * home :: [github.com/sportdb/footty](https://github.com/sportdb/footty)
5
+ * bugs :: [github.com/sportdb/footty/issues](https://github.com/sportdb/footty/issues)
6
+ * gem :: [rubygems.org/gems/fbtxt2json](https://rubygems.org/gems/fbtxt2json)
7
+ * rdoc :: [rubydoc.info/gems/fbtxt2json](http://rubydoc.info/gems/fbtxt2json)
8
+
4
9
 
5
10
  ## Step 0 - Installation Via Gems
6
11
 
@@ -24,10 +29,16 @@ resulting in:
24
29
  ```
25
30
  Usage: fbtxt2json [options] PATH
26
31
  --verbose, --debug turn on verbose / debug output (default: false)
27
- -o, --output PATH output to file
32
+ -o, --output PATH output to file / dir
28
33
  ```
29
34
 
30
35
 
36
+ Note - the football.txt to .json converter works in two modes. (1) you can pass in one or more files to concat(enate) into one .json output or (2) you can pass in one or more directories to convert all files (automagically) one-by-one.
37
+
38
+
39
+
40
+ ### Concat(enate) one or more files into one .json output
41
+
31
42
  Let's try to convert the "Euro" European Championship 2024
32
43
  in the Football.TXT format (see [`euro/2024--germany/euro.txt`](https://github.com/openfootball/euro/blob/master/2024--germany/euro.txt)) to JSON:
33
44
 
@@ -109,6 +120,55 @@ to output into a file use the `-o/--output` option:
109
120
  $ fbtxt2json england/2024-25/1-premierleague.txt -o en.json
110
121
  ```
111
122
 
123
+
124
+ ### (Auto-)convert one or more directories
125
+
126
+ Let's try to convert the England directory (repo), that is, all datafiles
127
+ in the Football.TXT format (see [`/england`](https://github.com/openfootball/england)) to JSON:
128
+
129
+ ```
130
+ $ fbtxt2json england
131
+ ```
132
+
133
+ resulting in:
134
+
135
+ ```
136
+ england/
137
+ 2024-25/
138
+ 1-premierleague.json
139
+ 2-championship.json
140
+ 3-league1.json
141
+ 4-league2.json
142
+ 5-nationalleague.json
143
+ eflcup.json
144
+ facup.json
145
+ ...
146
+ ```
147
+
148
+ Note - by default all `.txt` file extensions get changed to `.json`.
149
+ To use a different output directory use the `-o/--output` option. Example:
150
+
151
+ ```
152
+ $ fbtxt2json england -o ./o
153
+ ```
154
+
155
+ resulting in:
156
+
157
+ ```
158
+ o/
159
+ 2024-25/
160
+ 1-premierleague.json
161
+ 2-championship.json
162
+ 3-league1.json
163
+ 4-league2.json
164
+ 5-nationalleague.json
165
+ eflcup.json
166
+ facup.json
167
+ ...
168
+ ...
169
+ ```
170
+
171
+
112
172
  That's it.
113
173
 
114
174
 
data/Rakefile CHANGED
@@ -2,16 +2,15 @@ require 'hoe'
2
2
 
3
3
 
4
4
  Hoe.spec 'fbtxt2json' do
5
-
6
- self.version = '0.0.1'
5
+ self.version = '0.2.0'
7
6
 
8
7
  self.summary = "fbtxt2json - convert football.txt match schedules & more to json"
9
8
  self.description = summary
10
9
 
11
- self.urls = { home: 'https://github.com/sportdb/sport.db' }
10
+ self.urls = { home: 'https://github.com/sportdb/footty' }
12
11
 
13
12
  self.author = 'Gerald Bauer'
14
- self.email = 'gerald.bauer@gmail.com'
13
+ self.email = 'gerald.bauer@gmail.com'
15
14
 
16
15
  # switch extension to .markdown for gihub formatting
17
16
  self.readme_file = 'README.md'
@@ -20,7 +19,9 @@ Hoe.spec 'fbtxt2json' do
20
19
  self.licenses = ['Public Domain']
21
20
 
22
21
  self.extra_deps = [
23
- ['sportdb-quick', '>= 0.2.0'],
22
+ ['sportdb-quick', '>= 0.2.1'],
23
+ ### note - include fbtok gem for (shared) command-line helpers/machinery!!!
24
+ ['fbtok', '>= 0.3.3'],
24
25
  ]
25
26
 
26
27
  self.spec_extras = {
data/bin/fbtxt2json CHANGED
@@ -7,19 +7,21 @@
7
7
  ## our own code
8
8
  require 'sportdb/quick'
9
9
 
10
+ require 'fbtok' ### check if requires sportdb/quick (no need to duplicate)
11
+
10
12
 
11
13
 
12
14
  require 'optparse'
13
15
 
14
16
 
15
17
 
16
- args = ARGV
17
- opts = { debug: false,
18
+ args = ARGV
19
+ opts = { debug: false,
18
20
  output: nil,
19
- }
21
+ }
20
22
 
21
- parser = OptionParser.new do |parser|
22
- parser.banner = "Usage: #{$PROGRAM_NAME} [options] PATH"
23
+ parser = OptionParser.new do |parser|
24
+ parser.banner = "Usage: #{$PROGRAM_NAME} [options] PATH"
23
25
 
24
26
  ##
25
27
  ## check if git has a offline option?? (use same)
@@ -35,7 +37,7 @@ require 'optparse'
35
37
  end
36
38
 
37
39
  parser.on( "-o PATH", "--output PATH",
38
- "output to file" ) do |output|
40
+ "output to file / dir" ) do |output|
39
41
  opts[:output] = output
40
42
  end
41
43
  end
@@ -47,14 +49,11 @@ puts "ARGV:"
47
49
  p args
48
50
 
49
51
 
50
- path = if args.empty?
51
- '../../../openfootball/euro/2021--europe/euro.txt'
52
- elsif args.size == 1
53
- args[0]
54
- else
55
- puts "!! wrong number of args, got #{args.size} - #{args.inspect} - only one arg supported/expected"
56
- exit 1
57
- end
52
+ paths = if args.empty?
53
+ ['/sports/openfootball/euro/2021--europe/euro.txt']
54
+ else
55
+ args
56
+ end
58
57
 
59
58
 
60
59
  if opts[:debug]
@@ -67,27 +66,104 @@ else
67
66
  end
68
67
 
69
68
 
70
- puts "==> reading >#{path}<..."
71
- quick = SportDb::QuickMatchReader.new( read_text( path ) )
72
- matches = quick.parse
73
- name = quick.league_name ## quick hack - get league+season via league_name
69
+ ###
70
+ ## two modes - process directories or concat(enate)d files
71
+ ##
72
+ ## check if args is a directory
73
+ ##
74
+ dirs = 0
75
+ files = 0
76
+ paths.each do |path|
77
+ if Dir.exist?( path )
78
+ dirs += 1
79
+ elsif File.exist?( path )
80
+ files += 1
81
+ else ## not a file or dir repprt errr
82
+ raise ArgumentError, "file/dir does NOT exist - #{path}"
83
+ end
84
+ end
85
+
86
+ if dirs > 0 && files > 0
87
+ raise ArgumentError, "#{files} file(s), #{dirs} dir(s) - can only process dirs or files but NOT both; sorry"
88
+ end
74
89
 
75
- data = { 'name' => name,
76
- 'matches' => matches.map {|match| match.as_json }}
77
- pp data
78
- puts
79
- puts " #{matches.size} match(es)"
80
90
 
81
- if quick.errors?
82
- puts "!! #{quick.errors.size} parse error(s):"
83
- pp quick.errors
84
- exit 1
85
- end
86
91
 
87
- if opts[:output]
88
- puts "==> writing matches to #{opts[:output]}"
89
- write_json( opts[:output], data )
92
+ def parse( txt, dump: false ) ### check - name parse_txt or txt_to_json or such - why? why not?
93
+ quick = SportDb::QuickMatchReader.new( txt )
94
+ matches = quick.parse
95
+ name = quick.league_name ## quick hack - get league+season via league_name
96
+
97
+ data = { 'name' => name,
98
+ 'matches' => matches.map {|match| match.as_json }}
99
+
100
+ if dump
101
+ pp data
102
+ puts
103
+ end
104
+ puts " #{matches.size} match(es)"
105
+
106
+ if quick.errors?
107
+ puts "!! #{quick.errors.size} parse error(s):"
108
+ pp quick.errors
109
+ exit 1
110
+ end
111
+
112
+ data
113
+ end
114
+
115
+
116
+ if files > 0
117
+ ## step 1 - concat(enate) all text files into one
118
+ txt = String.new
119
+ paths.each_with_index do |path,i|
120
+ puts "==> reading file [#{i+1}/#{paths.size}] >#{path}<..."
121
+ txt += "\n\n" if i > 0
122
+ txt += read_text( path )
123
+ end
124
+
125
+ ## step 2 - parse (matches) in the football.txt format
126
+ data = parse( txt, dump: true )
127
+
128
+ if opts[:output]
129
+ puts "==> writing matches to #{opts[:output]}"
130
+ write_json( opts[:output], data )
131
+ end
132
+ elsif dirs > 0
133
+ paths.each_with_index do |path,i|
134
+ puts "==> reading dir [#{i+1}/#{paths.size}] >#{path}<..."
135
+
136
+ datafiles = SportDb::Parser::Opts._find( path )
137
+ pp datafiles
138
+ puts " #{datafiles.size} datafile(s)"
139
+
140
+ datafiles.each do |datafile|
141
+ txt = read_text( datafile )
142
+ data = parse( txt )
143
+
144
+ if opts[:output]
145
+ ### norm - File.expanddir !!!
146
+ reldir = File.expand_path(File.dirname( path )) ## keep last dir (in relative name)
147
+ relpath = datafile.sub( reldir+'/', '' )
148
+ dir = File.dirname( relpath )
149
+ ## puts " reldir = #{reldir}, datafile = #{datafile}"
150
+ ## puts " relpath = #{relpath}, dir = #{dir}"
151
+ basename = File.basename( relpath, File.extname(relpath))
152
+ outpath = "#{opts[:output]}/#{dir}/#{basename}.json"
153
+ else
154
+ dir = File.dirname( datafile )
155
+ basename = File.basename( datafile, File.extname(datafile) )
156
+ outpath = "#{dir}/#{basename}.json"
157
+ end
158
+ puts " writing matches to #{outpath}"
159
+ write_json( outpath, data )
90
160
  end
161
+ end
162
+ else
163
+ ## do nothing; no args
164
+ end
165
+
166
+
91
167
 
92
168
 
93
169
  puts "bye"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbtxt2json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-28 00:00:00.000000000 Z
11
+ date: 2025-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-quick
@@ -16,14 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.2.0
19
+ version: 0.2.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.2.0
26
+ version: 0.2.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: fbtok
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.3
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rdoc
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +64,14 @@ dependencies:
50
64
  requirements:
51
65
  - - "~>"
52
66
  - !ruby/object:Gem::Version
53
- version: '4.1'
67
+ version: '4.2'
54
68
  type: :development
55
69
  prerelease: false
56
70
  version_requirements: !ruby/object:Gem::Requirement
57
71
  requirements:
58
72
  - - "~>"
59
73
  - !ruby/object:Gem::Version
60
- version: '4.1'
74
+ version: '4.2'
61
75
  description: fbtxt2json - convert football.txt match schedules & more to json
62
76
  email: gerald.bauer@gmail.com
63
77
  executables:
@@ -73,7 +87,7 @@ files:
73
87
  - README.md
74
88
  - Rakefile
75
89
  - bin/fbtxt2json
76
- homepage: https://github.com/sportdb/sport.db
90
+ homepage: https://github.com/sportdb/footty
77
91
  licenses:
78
92
  - Public Domain
79
93
  metadata: {}
@@ -94,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
108
  - !ruby/object:Gem::Version
95
109
  version: '0'
96
110
  requirements: []
97
- rubygems_version: 3.4.10
111
+ rubygems_version: 3.5.22
98
112
  signing_key:
99
113
  specification_version: 4
100
114
  summary: fbtxt2json - convert football.txt match schedules & more to json