Skip to content

Instantly share code, notes, and snippets.

@JustinAiken
Created March 27, 2019 23:03
Show Gist options
  • Save JustinAiken/a335853cbc1998027f0b41636b0e8e5c to your computer and use it in GitHub Desktop.
Save JustinAiken/a335853cbc1998027f0b41636b0e8e5c to your computer and use it in GitHub Desktop.
# Need to set this up: Create a folder called "DLC" or something, fill in here:
DLC_FOLDER = "folder_custom_1542337448"
# Might need to set this up with full path if ~/ doesn't work for home
DB_LOCATION = "sqlite:///~/Library/Application%20Support/rs-manager/rsdb.sqlite"
require "bundler/inline"
gemfile do
source "https://rubygems.org"
gem "sequel"
gem "sqlite3"
gem "activesupport"
gem "pry"
gem "nokogiri"
gem "rainbow"
end
require "yaml"
require "sequel"
require "sqlite3"
require "uri"
require "active_support"
require "pry"
require "date"
require "nokogiri"
require "rainbow"
require "csv"
DB = Sequel.connect(DB_LOCATION)
class SetlistMeta < Sequel::Model(:setlist_meta)
def associated_setlist
Sequel::Model(key.to_sym)
end
def create_setlist!
DB.run "CREATE TABLE IF NOT EXISTS #{key} ( uniqkey char UNIQUE primary key, FOREIGN KEY(uniqkey) REFERENCES songs_owned(uniqkey));"
end
end
class SongOwned < Sequel::Model(:songs_owned); end
Arrangement = Struct.new(:artist, :song, :id)
data_to_import = CSV
.read("file.csv")
.inject({}) do |memo, row|
date = row[0] # Used to import setlist name
name = row[1] # Used to import setlist name
artist = row[2]
song = row[3]
id = row[4] # Used to import the actual file
dlc_name = "DLC #{date} #{name}"
memo[dlc_name] ||= []
memo[dlc_name] << Arrangement.new(artist, song, id)
memo
end
SetlistMeta.unrestrict_primary_key
data_to_import.each_with_index do |(dlc_name, arrangements), i|
ts = Date.parse(dlc_name[4..13]).to_time.to_i + i
key = "setlist_custom_#{ts}"
slm = nil
if existing = SetlistMeta.where(key: key).first
slm = existing
puts dlc_name
else
slm = SetlistMeta.create(
key: key,
name: URI.escape(dlc_name),
is_manual: "true",
is_generated: "false",
is_rssetlist: "false",
is_starred: "false",
is_folder: "false",
parent_folder: DLC_FOLDER,
sort_options: "[]"
)
puts Rainbow(dlc_name).green
end
slm.create_setlist!
setlist = slm.associated_setlist
setlist.unrestrict_primary_key
arrangements.each do |arr|
song = SongOwned.where(id: arr.id).first
uniqkey = song.uniqkey
if setlist.where(uniqkey: uniqkey).first
puts " #{arr.artist} - #{arr.song} (#{arr.id})"
else
setlist.insert(uniqkey: uniqkey)
puts Rainbow(" #{arr.artist} - #{arr.song} (#{arr.id})").green
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment