Created
July 16, 2017 20:14
-
-
Save spotlightishere/d74b563652882385b7c8c522d55abed6 to your computer and use it in GitHub Desktop.
Fixes the large mistake that was providers. https://rc24.xyz | https://github.com/fl0co/RC24-Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'mysql2' | |
require 'json' | |
require 'yaml' | |
# Please edit with your config.rb's provider_options. | |
data = {host: 'localhost', database: 'SpotBot', username: 'spotbot', password: 'password'} | |
client = Mysql2::Client.new(host: data[:host], username: data[:username], password: data[:password], database: data[:database]) | |
codes = {} | |
client.query('SELECT * from codes').each do |stored_data| | |
id = 0 | |
user_data = {} | |
stored_data.each do |name, data| | |
if name == 'user_id' | |
id = data.to_i | |
next | |
end | |
# Parse stored JSON data and set it to the related code array | |
begin | |
key_data = JSON.parse(data) | |
rescue | |
key_data = {} | |
end | |
next if key_data == {} | |
user_data[name.to_sym] = key_data | |
end | |
codes[id] = user_data | |
end | |
file_name = 'data/codes_dump.yml' | |
File.open(file_name, 'w+') do |f| | |
f.write(codes.to_yaml) | |
end | |
puts "If you didn't see any errors, the export has been successfully completed! Check #{file_name} for a dump of your database, and make sure it looks logicial.\n" + | |
'Make sure to comment on this gist if anything is broken!' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment