Guest User

Untitled

a guest
Oct 20th, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. #! /usr/bin/ruby
  2.  
  3. require 'logger'
  4. require 'fileutils'
  5. require 'net/ftp'
  6. require 'rubygems'
  7. require 'mysql2'
  8.  
  9. # logging setup
  10. log = Logger.new("/tmp/sql_load_log.log", 10, 1024000)
  11. log.level = Logger::INFO
  12.  
  13. # paths
  14. export_work_path ='/Users/pierce/Documents/MarketingScienceDepartment/clients/Numeric/Bayer/SAINTresults_exports/'
  15. classifications_work_path = '/Users/pierce/Documents/MarketingScienceDepartment/clients/Numeric/Bayer/SAINTclassifications_exports/'
  16. export_archive_path = '/Users/pierce/Documents/MarketingScienceDepartment/clients/Numeric/Bayer/SAINTresults_exports/archive'
  17. classifications_archive_path = '/Users/pierce/Documents/MarketingScienceDepartment/clients/Numeric/Bayer/SAINTclassifications_exports/archive'
  18. export_ftp_path = '/domains/marketingscience.co/bayer/saintReceive'
  19. classification_ftp_path = '/domains/marketingscience.co/bayer/saintReceive'
  20.  
  21. #client = Mysql2::Client.new(:host => "127.0.0.1", :username => "root", :password => "", :database => "bayer")
  22.  
  23.  
  24. #begin
  25. # Dir["#{export_work_path}/*.csv"].each do |file|
  26.  
  27. # results = client.query("LOAD DATA LOCAL INFILE '#{export_work_path}#{file}' INTO TABLE bayer.saint_export_results FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' LINES TERMINATED BY '\n' IGNORE 3 LINES (tracking_cd, page_views, visits, click_throughs, registration_complete, print_coupon, article_view, visitors) SET created_at = curdate(), filename = '#{file}';")
  28. # puts "#{file}: #{results.count}"
  29. # puts "Loaded file #{file}"
  30. # log.info("Loaded file #{file}")
  31. # FileUtils.remove(file)
  32. # puts "Deleted file #{file}"
  33. # log.info("Deleted file #{file}")
  34.  
  35. # end
  36. #end
  37.  
  38. # export
  39. begin
  40. Dir["#{export_work_path}/*.csv"].each do |file| # Dir.glob("#{export_work_path}"'*.zip') do |file|
  41. puts "test"
  42. query = ["mysql -u root -e ",'"',"LOAD DATA LOCAL INFILE '",file,"' INTO TABLE bayer.saint_export_results FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\\\"' LINES TERMINATED BY '\\n' IGNORE 3 LINES (tracking_cd, page_views, visits, click_throughs, registration_complete, print_coupon, article_view, visitors) SET created_at = curdate(), filename = '", file,"';\""].join
  43. puts "#{query}"
  44. system query
  45. puts "Loaded file #{file}"
  46. log.info("Loaded file #{file}")
  47. # FileUtils.remove(file)
  48. # puts "Deleted file #{file}"
  49. # log.info("Deleted file #{file}")
  50. end
  51. end
Add Comment
Please, Sign In to add comment