Skip to content

Instantly share code, notes, and snippets.

@tamr
Created February 16, 2012 20:00
Show Gist options
  • Save tamr/1847435 to your computer and use it in GitHub Desktop.
Save tamr/1847435 to your computer and use it in GitHub Desktop.
# Encoding: UTF-8
require "rubygems"
require 'httpclient'
URL = "http://m.habrahabr.ru/post/138291/"
habra = HTTPClient.new
text = habra.get(URL).http_body.content
begin
codes = text.scan /[a-z0-9]{12}/
rescue ArgumentError
codes = []
end
puts "==================================================="
f = File.open "used_codes.txt", "r"
used = []
f.each_line do |code|
codes.delete code.strip
end
f.close
dropbox = HTTPClient.new
login_page = dropbox.get("https://www.dropbox.com/login").http_body.content
t = login_page.match(/name=\"t\"\svalue\=\"(.+)\"/)[1]
dropbox.post("https://www.dropbox.com/login", { :t => t, :login_email => "flskif@gmail.com", :login_password => ""}).http_body.content
coupon_page = dropbox.get("https://www.dropbox.com/coupon").http_body.content
t = coupon_page.match(/name=\"t\"\svalue\=\"(.+)\"/)[1]
codes.each do |code|
puts "Trying #{code}"
coupon_page = dropbox.post("https://www.dropbox.com/coupon", { :t => t, :code => code}).http_body.content
t = coupon_page.match(/name=\"t\"\svalue\=\"(.+)\"/)[1]
puts coupon_page.match(/\<span\sclass\=\"error\-message\"\>(.+)\<\/span>/)[1]
end
# save used codes
f = File.open "used_codes.txt", "a"
codes.each do |code|
f.puts code
end
f.close
@littlewater
Copy link

nice codeseg!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment