Skip to content

Instantly share code, notes, and snippets.

/ex.rb Secret

Created February 26, 2013 18:58
Show Gist options
  • Save anonymous/1962238995d915baf04f to your computer and use it in GitHub Desktop.
Save anonymous/1962238995d915baf04f to your computer and use it in GitHub Desktop.
formatter = image.text.split("\n")
image_title = formatter
image_product_name = []
image_file_names = []
image_file_extension = []
image_file_size = []
image_title.each do |x|
image_product_name << x.gsub(/(CLEANING)/, '').gsub(/\(.*?\)/, '').gsub(/(Images)/, '').gsub(/(Hi-Res)/, '').gsub(/(Web-Ready)/, '')
end
image_urls = image.css('a').map { |link| link['href'] }
image_urls.each do |x|
system("wget #{x.strip}")
image_file_names << x.split('/').last
break
end
image_file_names.each do |x|
image_file_extension << File.extname(x)
image_file_size << File.stat(x).size
system("mv #{x} #{path}")
end
begin con = Mysql.new 'localhost', 'ruby', 'winrar', 'proresc'
image_product_name.each_index do |x|
q = "SELECT * FROM products WHERE name = '#{image_product_name[x].gsub(/(')/, "\'").strip}';"
rs = con.query(q)
if (rs.fetch_row == nil)
q = "INSERT INTO products (name) VALUES ('#{image_product_name[x].gsub(/(\')/, '').strip}';"
con.query(q)
puts q
end
q = "SELECT * FROM products WHERE name LIKE '#{image_product_name[x].gsub(/(\')/, '').strip}'"
rs = con.query(q)
puts q
q = "INSERT INTO documents (title, filetype, docgroup_id, doctype_id, product_id, store, filepath, filesize, deleted) VALUES ('#{image_title[x].gsub(/(\')/, '')}', '#{image_file_extension[x]}', 4, -1, rs.fetch_row[0], 'hex', '#{path}#{image_file_names}', #{image_file_size}, 0);"
con.query(q)
puts q
end
rescue Mysql::Error => e
puts e.errno
puts e.error
ensure
con.close if con
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment