Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'mysql2'
- ##########################################################################
- #
- # Script to insert new proxies into database from delimited .txt file
- #
- ##########################################################################
- ######## First let's connect to that sexy ass MySQL database ##############
- $proxy_database = Mysql2::Client.new(:host => 'localhost', :username => 'carpanda', :password => 'alexcarpanda')
- $proxy_database.query("USE proxy_database")
- #CREATE TABLE proxy_table (id INTEGER PRIMARY KEY NOT NULL, ip TEXT, port TEXT, alive_boolean BOOL);
- #inet_aton and inet_ntoa to convert ip to integer
- if $proxy_database
- puts "Successfully connected to proxy database"
- else
- puts "Bad connection to proxy databse, exiting..."
- return
- end
- ####### Parse the input file into ip and port array-> proxyList #######
- proxyFileList = File.new('6_19_2011.txt', 'r')
- proxyList = []
- while (proxy = proxyFileList.gets)
- proxy = proxy.split(/:|\n|\r/)
- proxyList << { 'ip' => proxy[0], 'port' => proxy[1]}
- end
- proxyFileList.close
- puts "Converted the mutha effin txt file"
- ######## Put the proxies from the text file into the DB if they are new #########
- for i in 0...proxyList.length
- $proxy_database.query("INSERT proxy_table (id,ip,port,alive_boolean) VALUES (inet_aton('#{proxyList[i]['ip']}'),'#{proxyList[i]['ip']}','#{proxyList[i]['port']}','1') ON DUPLICATE KEY UPDATE alive_boolean=1")
- end
- puts "Entered new proxies into db!"
Add Comment
Please, Sign In to add comment