Advertisement
Guest User

Untitled

a guest
Jul 16th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. require 'mysql2'
  2. require 'json'
  3. require 'yaml'
  4.  
  5. # Please edit with your config.rb's provider_options.
  6. data = {host: 'localhost', database: 'SpotBot', username: 'spotbot', password: 'FAba3a1EXE'}
  7. client = Mysql2::Client.new(host: data[:host], username: data[:username], password: data[:password], database: data[:database])
  8. codes = {}
  9. client.query('SELECT * from codes').each do |stored_data|
  10. id = 0
  11. user_data = {}
  12. stored_data.each do |name, data|
  13. if name == 'user_id'
  14. id = data.to_i
  15. next
  16. end
  17. # Parse stored JSON data and set it to the related code array
  18. begin
  19. key_data = JSON.parse(data)
  20. rescue
  21. key_data = {}
  22. end
  23. next if key_data == {}
  24. user_data[name.to_sym] = key_data
  25. end
  26. codes[id] = user_data
  27. end
  28. file_name = 'data/codes_dump.yml'
  29. File.open(file_name, 'w+') do |f|
  30. f.write(codes.to_yaml)
  31. end
  32. 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" +
  33. 'Make sure to comment on this gist if anything is broken!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement