unclekryon 0.4.9.pre.alpha → 0.4.12.pre.alpha
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.
- checksums.yaml +4 -4
- data/Gemfile +10 -26
- data/Gemfile.lock +20 -24
- data/README.md +3 -2
- data/Rakefile +11 -30
- data/bin/unclekryon +4 -15
- data/hax/kryon.yaml +28 -0
- data/hax/kryon_aums_2002-2005.yaml +460 -0
- data/hax/kryon_aums_2006.yaml +601 -0
- data/hax/kryon_aums_2007.yaml +1024 -0
- data/hax/kryon_aums_2008.yaml +950 -0
- data/hax/kryon_aums_2009.yaml +496 -0
- data/hax/kryon_aums_2010.yaml +1443 -0
- data/hax/kryon_aums_2011.yaml +1458 -0
- data/hax/kryon_aums_2012.yaml +2123 -0
- data/hax/kryon_aums_2013.yaml +1647 -0
- data/hax/kryon_aums_2014.yaml +2478 -0
- data/hax/kryon_aums_2015.yaml +3386 -0
- data/hax/kryon_aums_2016.yaml +3476 -0
- data/hax/kryon_aums_2017.yaml +3712 -0
- data/hax/kryon_aums_2018.yaml +3654 -0
- data/lib/unclekryon/data/album_data.rb +74 -82
- data/lib/unclekryon/data/artist_data.rb +24 -36
- data/lib/unclekryon/data/artist_data_data.rb +29 -41
- data/lib/unclekryon/data/aum_data.rb +20 -32
- data/lib/unclekryon/data/base_data.rb +27 -39
- data/lib/unclekryon/data/pic_data.rb +25 -37
- data/lib/unclekryon/data/release_data.rb +14 -26
- data/lib/unclekryon/data/social_data.rb +6 -18
- data/lib/unclekryon/data/timespan_data.rb +16 -28
- data/lib/unclekryon/dev_opts.rb +7 -19
- data/lib/unclekryon/hacker.rb +121 -135
- data/lib/unclekryon/iso/base_iso.rb +69 -81
- data/lib/unclekryon/iso/can_prov_terr.rb +34 -47
- data/lib/unclekryon/iso/country.rb +34 -51
- data/lib/unclekryon/iso/language.rb +84 -98
- data/lib/unclekryon/iso/region.rb +8 -29
- data/lib/unclekryon/iso/subregion.rb +8 -29
- data/lib/unclekryon/iso/usa_state.rb +28 -41
- data/lib/unclekryon/iso.rb +128 -138
- data/lib/unclekryon/jsoner.rb +31 -50
- data/lib/unclekryon/log.rb +34 -46
- data/lib/unclekryon/parsers/kryon_aum_year_album_parser.rb +163 -167
- data/lib/unclekryon/parsers/kryon_aum_year_parser.rb +122 -127
- data/lib/unclekryon/server.rb +8 -17
- data/lib/unclekryon/trainer.rb +68 -85
- data/lib/unclekryon/uploader.rb +8 -17
- data/lib/unclekryon/util.rb +80 -92
- data/lib/unclekryon/version.rb +4 -16
- data/lib/unclekryon.rb +166 -166
- data/train/kryon.yaml +6077 -0
- data/unclekryon.gemspec +49 -49
- metadata +50 -22
data/lib/unclekryon/iso.rb
CHANGED
|
@@ -1,28 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
1
|
# encoding: UTF-8
|
|
3
2
|
# frozen_string_literal: true
|
|
4
3
|
|
|
5
4
|
#--
|
|
6
5
|
# This file is part of UncleKryon-server.
|
|
7
|
-
# Copyright (c) 2018-
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
12
|
-
# (at your option) any later version.
|
|
13
|
-
#
|
|
14
|
-
# UncleKryon-server is distributed in the hope that it will be useful,
|
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
# GNU General Public License for more details.
|
|
18
|
-
#
|
|
19
|
-
# You should have received a copy of the GNU General Public License
|
|
20
|
-
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
|
6
|
+
# Copyright (c) 2018-2021 Jonathan Bradley Whited
|
|
7
|
+
#
|
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
21
9
|
#++
|
|
22
10
|
|
|
23
11
|
|
|
24
|
-
require 'bundler/setup'
|
|
25
|
-
|
|
26
12
|
require 'yaml'
|
|
27
13
|
|
|
28
14
|
require 'unclekryon/dev_opts'
|
|
@@ -43,7 +29,7 @@ module UncleKryon
|
|
|
43
29
|
class Iso
|
|
44
30
|
DEFAULT_FILEPATH = "#{BaseIsos::DEFAULT_DIR}/iso.yaml"
|
|
45
31
|
ID = 'ISO'
|
|
46
|
-
|
|
32
|
+
|
|
47
33
|
@@can_provs_terrs = nil
|
|
48
34
|
@@countries = nil
|
|
49
35
|
@@iso = nil
|
|
@@ -51,42 +37,43 @@ module UncleKryon
|
|
|
51
37
|
@@regions = nil
|
|
52
38
|
@@subregions = nil
|
|
53
39
|
@@usa_states = nil
|
|
54
|
-
|
|
40
|
+
|
|
55
41
|
attr_accessor :updated_can_provs_terrs_on
|
|
56
42
|
attr_accessor :updated_countries_on
|
|
57
43
|
attr_accessor :updated_languages_on
|
|
58
44
|
attr_accessor :updated_regions_on
|
|
59
45
|
attr_accessor :updated_subregions_on
|
|
60
46
|
attr_accessor :updated_usa_states_on
|
|
61
|
-
|
|
62
|
-
def initialize
|
|
47
|
+
|
|
48
|
+
def initialize
|
|
63
49
|
super()
|
|
64
|
-
|
|
65
|
-
update_all
|
|
50
|
+
|
|
51
|
+
update_all
|
|
66
52
|
end
|
|
67
|
-
|
|
68
|
-
def self.can_provs_terrs
|
|
53
|
+
|
|
54
|
+
def self.can_provs_terrs
|
|
69
55
|
if !@@can_provs_terrs
|
|
70
|
-
@@can_provs_terrs = CanProvsTerrs.load_file
|
|
56
|
+
@@can_provs_terrs = CanProvsTerrs.load_file
|
|
71
57
|
end
|
|
72
58
|
return @@can_provs_terrs
|
|
73
59
|
end
|
|
74
|
-
|
|
75
|
-
def self.countries
|
|
60
|
+
|
|
61
|
+
def self.countries
|
|
76
62
|
if !@@countries
|
|
77
|
-
@@countries = Countries.load_file
|
|
63
|
+
@@countries = Countries.load_file
|
|
78
64
|
end
|
|
79
65
|
return @@countries
|
|
80
66
|
end
|
|
81
|
-
|
|
67
|
+
|
|
82
68
|
def self.find_kryon_locations(text)
|
|
83
69
|
locs = []
|
|
84
|
-
|
|
70
|
+
|
|
85
71
|
# Fix bad data
|
|
86
|
-
text = text.gsub(/\A[[:space:]]*SASKATOON\-CALGARY[[:space:]]*\z/,
|
|
87
|
-
|
|
72
|
+
text = text.gsub(/\A[[:space:]]*SASKATOON\-CALGARY[[:space:]]*\z/,
|
|
73
|
+
'SASKATOON, SASKATCHEWAN, CANADA / CALGARY, ALBERTA, CANADA')
|
|
74
|
+
|
|
88
75
|
# Multiple countries are separated by '/' or '&'
|
|
89
|
-
text.split(
|
|
76
|
+
text.split(%r{[[:space:]]*[/\&][[:space:]]*}).each do |t|
|
|
90
77
|
# Fix misspellings and/or weird shortenings
|
|
91
78
|
t = t.gsub(/Kansas[[:space:]]*\,[[:space:]]*City/i,'Kansas City')
|
|
92
79
|
t = t.gsub(/[\+\*]+/,'') # Means more countries, but won't worry about it (since not listed)
|
|
@@ -95,9 +82,12 @@ module UncleKryon
|
|
|
95
82
|
t = t.gsub(/\A[[:space:]]*NEWPORT[[:space:]]+BEACH[[:space:]]*\z/,'Newport Beach, California')
|
|
96
83
|
t = t.gsub(/\A[[:space:]]*SAN[[:space:]]+RAFAEL[[:space:]]*\z/,'San Rafael, California')
|
|
97
84
|
t = t.gsub(/\A[[:space:]]*MILANO\,[[:space:]]*MARITTIMA[[:space:]]*\z/,'MILANO MARITTIMA, ITALY')
|
|
98
|
-
t = t.gsub(/\A[[:space:]]*MAR[[:space:]]+DEL[[:space:]]+PLATA[[:space:]]*\z/,
|
|
99
|
-
|
|
100
|
-
t = t.gsub(/\A[[:space:]]*
|
|
85
|
+
t = t.gsub(/\A[[:space:]]*MAR[[:space:]]+DEL[[:space:]]+PLATA[[:space:]]*\z/,
|
|
86
|
+
'MAR DEL PLATA, ARGENTINA')
|
|
87
|
+
t = t.gsub(/\A[[:space:]]*PATAGONIA[[:space:]]+CRUISE[[:space:]]+2012[[:space:]]*\z/,
|
|
88
|
+
'Patagonia, South America')
|
|
89
|
+
t = t.gsub(/\A[[:space:]]*PHILADELPHIA,[[:space:]]+PENNSYLVANNIA[[:space:]]*\z/,
|
|
90
|
+
'Philadelphia, Pennsylvania')
|
|
101
91
|
t = t.gsub(/\ATHE[[:space:]]+AWAKENING[[:space:]]+ZONE.COM\z/,'World')
|
|
102
92
|
t = t.gsub(/\ASEDONA, AZ - Summer Light Conference\z/,'Sedona, AZ')
|
|
103
93
|
t = t.gsub(/\AHAWAII CRUISE 11\z/,'Hawaii')
|
|
@@ -113,72 +103,72 @@ module UncleKryon
|
|
|
113
103
|
t = t.gsub(/\AHAWAI\'I\s+CRUISE\s+[[:digit:]]+\z/i,'Hawaii')
|
|
114
104
|
t = t.gsub(/\AALASKA\s+CRUISE\s+[[:digit:]]+\z/i,'Alaska')
|
|
115
105
|
t = t.gsub(/\AGLASS\s+HOUSE\s+MT\.\s+\(AU\)\z/i,'Glass House Mountains, Australia')
|
|
116
|
-
|
|
106
|
+
|
|
117
107
|
parts = t.split(/[[:space:]\,\-]+/)
|
|
118
108
|
last = parts.last
|
|
119
|
-
last2 = (parts.length
|
|
120
|
-
|
|
109
|
+
last2 = (parts.length >= 2) ? (parts[-2] + last) : nil
|
|
110
|
+
|
|
121
111
|
city = nil
|
|
122
112
|
state = nil
|
|
123
|
-
country = countries
|
|
113
|
+
country = countries.find_by_name(last) # By name because e.g. code CO is Colorado and Colombia
|
|
124
114
|
subregion = nil
|
|
125
115
|
region = nil
|
|
126
|
-
|
|
116
|
+
|
|
127
117
|
parse_state = true
|
|
128
|
-
state_i = parts.length
|
|
129
|
-
|
|
118
|
+
state_i = parts.length - 1
|
|
119
|
+
|
|
130
120
|
# USA state?
|
|
131
|
-
if country.nil?
|
|
121
|
+
if country.nil?
|
|
132
122
|
parse_state = false
|
|
133
|
-
state = usa_states
|
|
134
|
-
|
|
135
|
-
if state.nil?
|
|
136
|
-
state = usa_states
|
|
137
|
-
state_i = parts.length
|
|
123
|
+
state = usa_states.find(last)
|
|
124
|
+
|
|
125
|
+
if state.nil? && !last2.nil?
|
|
126
|
+
state = usa_states.find_by_name(last2)
|
|
127
|
+
state_i = parts.length - 2 unless state.nil?
|
|
138
128
|
end
|
|
139
|
-
|
|
140
|
-
if state.nil?
|
|
129
|
+
|
|
130
|
+
if state.nil?
|
|
141
131
|
# CAN prov/terr? (use state var)
|
|
142
|
-
state = can_provs_terrs
|
|
143
|
-
|
|
144
|
-
if state.nil?
|
|
145
|
-
state = can_provs_terrs
|
|
146
|
-
state_i = parts.length
|
|
132
|
+
state = can_provs_terrs.find(last)
|
|
133
|
+
|
|
134
|
+
if state.nil? && !last2.nil?
|
|
135
|
+
state = can_provs_terrs.find_by_name(last2)
|
|
136
|
+
state_i = parts.length - 2 unless state.nil?
|
|
147
137
|
end
|
|
148
|
-
|
|
149
|
-
if state.nil?
|
|
138
|
+
|
|
139
|
+
if state.nil?
|
|
150
140
|
# Try country code
|
|
151
|
-
country = countries
|
|
152
|
-
|
|
153
|
-
if country.nil?
|
|
154
|
-
country = countries
|
|
155
|
-
state_i = 0 unless country.nil?
|
|
141
|
+
country = countries.find_by_code(last) # Try by code; e.g., CAN for Canada
|
|
142
|
+
|
|
143
|
+
if country.nil?
|
|
144
|
+
country = countries.find_by_name(t)
|
|
145
|
+
state_i = 0 unless country.nil?
|
|
156
146
|
end
|
|
157
|
-
if country.nil?
|
|
158
|
-
country = countries
|
|
159
|
-
state_i = 0 unless country.nil?
|
|
147
|
+
if country.nil? && !last2.nil?
|
|
148
|
+
country = countries.find_by_name(last2)
|
|
149
|
+
state_i = 0 unless country.nil?
|
|
160
150
|
end
|
|
161
|
-
|
|
162
|
-
if country.nil?
|
|
151
|
+
|
|
152
|
+
if country.nil?
|
|
163
153
|
# Subregion?
|
|
164
|
-
subregion = subregions
|
|
165
|
-
|
|
166
|
-
if subregion.nil?
|
|
167
|
-
subregion = subregions
|
|
154
|
+
subregion = subregions.find_by_name(t)
|
|
155
|
+
|
|
156
|
+
if subregion.nil? && !last2.nil?
|
|
157
|
+
subregion = subregions.find_by_name(last2)
|
|
168
158
|
end
|
|
169
|
-
|
|
170
|
-
if subregion.nil?
|
|
159
|
+
|
|
160
|
+
if subregion.nil?
|
|
171
161
|
# Region?
|
|
172
|
-
region = regions
|
|
173
|
-
|
|
174
|
-
if region.nil?
|
|
175
|
-
region = regions
|
|
162
|
+
region = regions.find_by_name(t)
|
|
163
|
+
|
|
164
|
+
if region.nil? && !last2.nil?
|
|
165
|
+
region = regions.find_by_name(last2)
|
|
176
166
|
end
|
|
177
|
-
|
|
178
|
-
if region.nil?
|
|
167
|
+
|
|
168
|
+
if region.nil?
|
|
179
169
|
msg = %Q(No state/country/region: "#{text}","#{t}","#{last}")
|
|
180
|
-
|
|
181
|
-
if DevOpts.instance.dev?
|
|
170
|
+
|
|
171
|
+
if DevOpts.instance.dev?
|
|
182
172
|
raise msg
|
|
183
173
|
else
|
|
184
174
|
log.warn(msg)
|
|
@@ -197,111 +187,111 @@ module UncleKryon
|
|
|
197
187
|
end
|
|
198
188
|
else
|
|
199
189
|
state = state.code
|
|
200
|
-
country = countries
|
|
190
|
+
country = countries.find_by_code('CAN').code
|
|
201
191
|
end
|
|
202
192
|
else
|
|
203
193
|
state = state.code
|
|
204
|
-
country = countries
|
|
194
|
+
country = countries.find_by_code('USA').code
|
|
205
195
|
end
|
|
206
196
|
else
|
|
207
197
|
country = country.code
|
|
208
198
|
end
|
|
209
|
-
|
|
210
|
-
if region.nil?
|
|
199
|
+
|
|
200
|
+
if region.nil? || subregion.nil?
|
|
211
201
|
# Not USA
|
|
212
202
|
if parse_state
|
|
213
|
-
if parts.length
|
|
214
|
-
state = parts[-2].gsub(/[[:space:]]+/,' ').strip
|
|
215
|
-
|
|
203
|
+
if parts.length >= 2
|
|
204
|
+
state = parts[-2].gsub(/[[:space:]]+/,' ').strip
|
|
205
|
+
|
|
216
206
|
# CAN prov/terr? (use state var)
|
|
217
|
-
if country == countries
|
|
218
|
-
state = can_provs_terrs
|
|
219
|
-
|
|
220
|
-
if state.nil?
|
|
221
|
-
if parts.length
|
|
222
|
-
state = can_provs_terrs
|
|
223
|
-
state_i = parts.length
|
|
207
|
+
if country == countries.find_by_code('CAN').code
|
|
208
|
+
state = can_provs_terrs.find(state)
|
|
209
|
+
|
|
210
|
+
if state.nil?
|
|
211
|
+
if parts.length >= 3
|
|
212
|
+
state = can_provs_terrs.find_by_name(parts[-3] + parts[-2])
|
|
213
|
+
state_i = parts.length - 3 unless state.nil?
|
|
224
214
|
end
|
|
225
215
|
else
|
|
226
216
|
state = state.code
|
|
227
|
-
state_i = parts.length
|
|
217
|
+
state_i = parts.length - 2
|
|
228
218
|
end
|
|
229
219
|
else
|
|
230
|
-
if state.length
|
|
231
|
-
state = state.upcase
|
|
232
|
-
state_i = parts.length
|
|
220
|
+
if state.length == 2
|
|
221
|
+
state = state.upcase
|
|
222
|
+
state_i = parts.length - 2
|
|
233
223
|
else
|
|
234
224
|
state = nil
|
|
235
225
|
end
|
|
236
226
|
end
|
|
237
227
|
end
|
|
238
228
|
end
|
|
239
|
-
|
|
229
|
+
|
|
240
230
|
# City
|
|
241
231
|
city = []
|
|
242
|
-
|
|
243
|
-
c = parts[i].gsub(/[[:space:]]+/,' ').strip
|
|
244
|
-
city.push(c) unless c.empty?
|
|
232
|
+
(0...state_i).each do |i|
|
|
233
|
+
c = parts[i].gsub(/[[:space:]]+/,' ').strip
|
|
234
|
+
city.push(c) unless c.empty?
|
|
245
235
|
end
|
|
246
|
-
city = city.compact
|
|
247
|
-
city = city.empty?
|
|
248
|
-
|
|
236
|
+
city = city.compact
|
|
237
|
+
city = city.empty? ? nil : city.map(&:capitalize).join(' ')
|
|
238
|
+
|
|
249
239
|
# Region
|
|
250
|
-
if !country.nil?
|
|
251
|
-
region = countries
|
|
240
|
+
if !country.nil?
|
|
241
|
+
region = countries.find_by_code(country).region
|
|
252
242
|
end
|
|
253
243
|
end
|
|
254
|
-
|
|
244
|
+
|
|
255
245
|
# Location
|
|
256
246
|
loc = [city,state,country,subregion,region] # Don't do compact(); we want all 4 ','
|
|
257
|
-
locs.push(loc.join(',')) unless loc.compact
|
|
247
|
+
locs.push(loc.join(',')) unless loc.compact.empty?
|
|
258
248
|
end
|
|
259
|
-
|
|
260
|
-
return locs.empty?
|
|
249
|
+
|
|
250
|
+
return locs.empty? ? nil : locs
|
|
261
251
|
end
|
|
262
|
-
|
|
263
|
-
def self.iso
|
|
252
|
+
|
|
253
|
+
def self.iso
|
|
264
254
|
if !@@iso
|
|
265
|
-
@@iso = Iso.load_file
|
|
255
|
+
@@iso = Iso.load_file
|
|
266
256
|
end
|
|
267
257
|
return @@iso
|
|
268
258
|
end
|
|
269
|
-
|
|
270
|
-
def self.languages
|
|
259
|
+
|
|
260
|
+
def self.languages
|
|
271
261
|
if !@@languages
|
|
272
|
-
@@languages = Languages.load_file
|
|
262
|
+
@@languages = Languages.load_file
|
|
273
263
|
end
|
|
274
264
|
return @@languages
|
|
275
265
|
end
|
|
276
|
-
|
|
266
|
+
|
|
277
267
|
def self.load_file(filepath=DEFAULT_FILEPATH)
|
|
278
268
|
y = YAML.load_file(filepath)
|
|
279
269
|
iso = y[ID]
|
|
280
270
|
return iso
|
|
281
271
|
end
|
|
282
|
-
|
|
283
|
-
def self.regions
|
|
272
|
+
|
|
273
|
+
def self.regions
|
|
284
274
|
if !@@regions
|
|
285
|
-
@@regions = Regions.load_file
|
|
275
|
+
@@regions = Regions.load_file
|
|
286
276
|
end
|
|
287
277
|
return @@regions
|
|
288
278
|
end
|
|
289
|
-
|
|
279
|
+
|
|
290
280
|
def save_to_file(filepath=DEFAULT_FILEPATH)
|
|
291
281
|
File.open(filepath,'w') do |f|
|
|
292
|
-
iso = {ID=>self}
|
|
282
|
+
iso = {ID => self}
|
|
293
283
|
YAML.dump(iso,f)
|
|
294
284
|
end
|
|
295
285
|
end
|
|
296
|
-
|
|
297
|
-
def self.subregions
|
|
286
|
+
|
|
287
|
+
def self.subregions
|
|
298
288
|
if !@@subregions
|
|
299
|
-
@@subregions = Subregions.load_file
|
|
289
|
+
@@subregions = Subregions.load_file
|
|
300
290
|
end
|
|
301
291
|
return @@subregions
|
|
302
292
|
end
|
|
303
|
-
|
|
304
|
-
def update_all
|
|
293
|
+
|
|
294
|
+
def update_all
|
|
305
295
|
@updated_can_provs_terrs_on = BaseData.max_updated_on_s(self.class.can_provs_terrs.values)
|
|
306
296
|
@updated_countries_on = BaseData.max_updated_on_s(self.class.countries.values)
|
|
307
297
|
@updated_languages_on = BaseData.max_updated_on_s(self.class.languages.values)
|
|
@@ -309,16 +299,16 @@ module UncleKryon
|
|
|
309
299
|
@updated_subregions_on = BaseData.max_updated_on_s(self.class.subregions.values)
|
|
310
300
|
@updated_usa_states_on = BaseData.max_updated_on_s(self.class.usa_states.values)
|
|
311
301
|
end
|
|
312
|
-
|
|
313
|
-
def self.usa_states
|
|
302
|
+
|
|
303
|
+
def self.usa_states
|
|
314
304
|
if !@@usa_states
|
|
315
|
-
@@usa_states = UsaStates.load_file
|
|
305
|
+
@@usa_states = UsaStates.load_file
|
|
316
306
|
end
|
|
317
307
|
return @@usa_states
|
|
318
308
|
end
|
|
319
|
-
|
|
320
|
-
def to_s
|
|
321
|
-
s = 'Updated On:'.dup
|
|
309
|
+
|
|
310
|
+
def to_s
|
|
311
|
+
s = 'Updated On:'.dup
|
|
322
312
|
s << "\n- CAN Provs/Terrs: #{@updated_can_provs_terrs_on}"
|
|
323
313
|
s << "\n- Countries: #{@updated_countries_on}"
|
|
324
314
|
s << "\n- Languages: #{@updated_languages_on}"
|
|
@@ -330,7 +320,7 @@ module UncleKryon
|
|
|
330
320
|
end
|
|
331
321
|
end
|
|
332
322
|
|
|
333
|
-
if $
|
|
323
|
+
if $PROGRAM_NAME == __FILE__
|
|
334
324
|
puts UncleKryon::Iso.can_provs_terrs['ON']
|
|
335
325
|
puts UncleKryon::Iso.countries['USA']
|
|
336
326
|
puts UncleKryon::Iso.languages['eng']
|
data/lib/unclekryon/jsoner.rb
CHANGED
|
@@ -1,33 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
1
|
# encoding: UTF-8
|
|
3
2
|
# frozen_string_literal: true
|
|
4
3
|
|
|
5
4
|
#--
|
|
6
5
|
# This file is part of UncleKryon-server.
|
|
7
|
-
# Copyright (c) 2020 Jonathan Bradley Whited
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
# it under the terms of the GNU General Public License as published by
|
|
11
|
-
# the Free Software Foundation, either version 3 of the License, or
|
|
12
|
-
# (at your option) any later version.
|
|
13
|
-
#
|
|
14
|
-
# UncleKryon-server is distributed in the hope that it will be useful,
|
|
15
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
-
# GNU General Public License for more details.
|
|
18
|
-
#
|
|
19
|
-
# You should have received a copy of the GNU General Public License
|
|
20
|
-
# along with UncleKryon-server. If not, see <https://www.gnu.org/licenses/>.
|
|
6
|
+
# Copyright (c) 2020-2021 Jonathan Bradley Whited
|
|
7
|
+
#
|
|
8
|
+
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
21
9
|
#++
|
|
22
10
|
|
|
23
11
|
|
|
24
|
-
IS_SCRIPT = $0 == __FILE__
|
|
25
|
-
|
|
26
|
-
if IS_SCRIPT
|
|
27
|
-
require 'rubygems'
|
|
28
|
-
require 'bundler/setup'
|
|
29
|
-
end
|
|
30
|
-
|
|
31
12
|
require 'json'
|
|
32
13
|
require 'yaml'
|
|
33
14
|
|
|
@@ -41,84 +22,84 @@ module UncleKryon
|
|
|
41
22
|
class Jsoner
|
|
42
23
|
def jsonify_all(pretty=false)
|
|
43
24
|
json = {}
|
|
44
|
-
|
|
25
|
+
|
|
45
26
|
#jsonify_iso(json)
|
|
46
27
|
jsonify_artists(json)
|
|
47
|
-
|
|
48
|
-
return pretty ? JSON.pretty_generate(json) : json.to_json
|
|
28
|
+
|
|
29
|
+
return pretty ? JSON.pretty_generate(json) : json.to_json
|
|
49
30
|
end
|
|
50
|
-
|
|
31
|
+
|
|
51
32
|
def jsonify_artists(json)
|
|
52
33
|
json['aum'] = {}
|
|
53
34
|
json['scroll'] = {}
|
|
54
35
|
json['vision'] = {}
|
|
55
36
|
json['pic'] = {}
|
|
56
|
-
|
|
37
|
+
|
|
57
38
|
kryon = to_hash(ArtistData.load_file(File.join('hax','kryon.yaml')))
|
|
58
|
-
|
|
39
|
+
|
|
59
40
|
kryon['release'] = {}
|
|
60
41
|
kryon['album'] = {}
|
|
61
|
-
|
|
42
|
+
|
|
62
43
|
jsonify_artist_data(json,kryon,File.join('hax','kryon_aums_2002-2005.yaml'))
|
|
63
|
-
|
|
44
|
+
|
|
64
45
|
json['artist'] = {
|
|
65
46
|
kryon['id'] => kryon
|
|
66
47
|
}
|
|
67
48
|
end
|
|
68
|
-
|
|
49
|
+
|
|
69
50
|
def jsonify_artist_data(json,artist,file)
|
|
70
51
|
data = ArtistDataData.load_file(file)
|
|
71
|
-
|
|
72
|
-
data.albums.each
|
|
73
|
-
album.aums.each
|
|
52
|
+
|
|
53
|
+
data.albums.each do |album_id,album|
|
|
54
|
+
album.aums.each do |aum_id,aum|
|
|
74
55
|
json[ArtistDataData::AUMS_ID][aum_id] = to_hash(aum)
|
|
75
56
|
end
|
|
76
57
|
album.aums = album.aums.keys
|
|
77
|
-
|
|
78
|
-
album.pics.each
|
|
58
|
+
|
|
59
|
+
album.pics.each do |pic_id,pic|
|
|
79
60
|
json[ArtistDataData::PICS_ID][pic_id] = to_hash(pic)
|
|
80
61
|
end
|
|
81
62
|
album.pics = album.pics.keys
|
|
82
63
|
end
|
|
83
|
-
|
|
64
|
+
|
|
84
65
|
artist[ArtistDataData::ALBUMS_ID] = to_hash(data.albums)
|
|
85
|
-
|
|
66
|
+
|
|
86
67
|
#attr_accessor :scrolls
|
|
87
68
|
#attr_accessor :visions
|
|
88
69
|
end
|
|
89
|
-
|
|
70
|
+
|
|
90
71
|
def jsonify_iso(json)
|
|
91
72
|
json['iso'] = to_hash(Iso.iso)
|
|
92
|
-
json['
|
|
73
|
+
json['can_proterr'] = to_hash(Iso.can_provs_terrs.values)
|
|
93
74
|
json['country'] = to_hash(Iso.countries.values)
|
|
94
75
|
json['language'] = to_hash(Iso.languages.values)
|
|
95
76
|
json['region'] = to_hash(Iso.regions.values)
|
|
96
77
|
json['subregion'] = to_hash(Iso.subregions.values)
|
|
97
78
|
json['usa_state'] = to_hash(Iso.usa_states.values)
|
|
98
79
|
end
|
|
99
|
-
|
|
80
|
+
|
|
100
81
|
def to_hash(obj)
|
|
101
82
|
hash = {}
|
|
102
|
-
|
|
83
|
+
|
|
103
84
|
if obj.respond_to?(:instance_variables) && obj.instance_variables.length > 0
|
|
104
|
-
obj.instance_variables.each
|
|
105
|
-
hash[var.to_s
|
|
85
|
+
obj.instance_variables.each do |var|
|
|
86
|
+
hash[var.to_s.delete('@')] = to_hash(obj.instance_variable_get(var))
|
|
106
87
|
end
|
|
107
88
|
elsif obj.is_a?(Hash)
|
|
108
|
-
obj.each
|
|
89
|
+
obj.each do |k,v|
|
|
109
90
|
hash[k] = to_hash(v)
|
|
110
91
|
end
|
|
111
92
|
else
|
|
112
|
-
return Util.empty_s?(obj.to_s
|
|
93
|
+
return Util.empty_s?(obj.to_s) ? nil : obj
|
|
113
94
|
end
|
|
114
|
-
|
|
95
|
+
|
|
115
96
|
return hash
|
|
116
97
|
end
|
|
117
98
|
end
|
|
118
99
|
end
|
|
119
100
|
|
|
120
|
-
if
|
|
121
|
-
j = UncleKryon::Jsoner.new
|
|
122
|
-
|
|
101
|
+
if $PROGRAM_NAME == __FILE__
|
|
102
|
+
j = UncleKryon::Jsoner.new
|
|
103
|
+
|
|
123
104
|
puts j.jsonify_all(true)
|
|
124
105
|
end
|