VRFS-3936

tweaking mobile jamtracks json formatting
This commit is contained in:
Jonathan Kolyer 2017-05-24 21:31:29 -07:00
parent cc6da7127a
commit 34b6887a79
1 changed files with 18 additions and 2 deletions

View File

@ -13,7 +13,7 @@ namespace :mobile do
end end
unless File.exists?(tmp_fname) unless File.exists?(tmp_fname)
puts "*** ERROR: download failed: `#{cmd}`" $stderr.puts "*** ERROR: download failed: `#{cmd}`"
return return
end end
@ -52,6 +52,8 @@ namespace :mobile do
artist: {}, artist: {},
} }
} }
indices = jtx_json[:jtx_indices]
CSV.foreach(tmp_fname) do |row| CSV.foreach(tmp_fname) do |row|
jtartist = row[0] jtartist = row[0]
@ -66,12 +68,12 @@ namespace :mobile do
artist: jtartist, artist: jtartist,
genre: jt.genres.map(&:description).join(', '), genre: jt.genres.map(&:description).join(', '),
id: jt.id, id: jt.id,
key: jt.id,
name: jtname, name: jtname,
plan_code: jt.plan_code, plan_code: jt.plan_code,
year: jt.year year: jt.year
} }
# jtx_json[:jtx_data] << jtdata # jtx_json[:jtx_data] << jtdata
indices = jtx_json[:jtx_indices]
first_char = jtartist[0].upcase first_char = jtartist[0].upcase
if (1..9) === first_char.to_i || '0' == first_char if (1..9) === first_char.to_i || '0' == first_char
@ -90,6 +92,20 @@ namespace :mobile do
idx_artist << jtdata idx_artist << jtdata
end end
alphanum = indices[:alphanum]
songs = []
alphanum.keys.sort.each do |key|
songs << { key: key, data: alphanum[key] }
end
indices[:alphanum] = songs
artists = indices[:artist]
artists_new = []
artists.keys.sort.each do |key|
artists_new << { key: key, data: artists[key] }
end
indices[:artist] = artists_new
File.open("#{Rails.root}/tmp/jtx_indices.json", 'w') do |ff| File.open("#{Rails.root}/tmp/jtx_indices.json", 'w') do |ff|
ff.write jtx_json.to_json ff.write jtx_json.to_json
end end