Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'mysql2'
- require 'json'
- require 'yaml'
- # Please edit with your config.rb's provider_options.
- data = {host: 'localhost', database: 'SpotBot', username: 'spotbot', password: 'FAba3a1EXE'}
- 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!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement