Created
December 11, 2009 13:32
-
-
Save avsej/254207 to your computer and use it in GitHub Desktop.
Automate rubymine license fetching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'net/http' | |
require 'digest/md5' | |
require 'pp' | |
begin | |
require 'faker' | |
rescue LoadError | |
puts "You should install faker gem. (gem install faker)" | |
exit | |
end | |
jetbrains_uri = URI.parse("http://www.jetbrains.com/eforms/rmEvaluation.action") | |
login = "e#{Digest::MD5.hexdigest(Time.now.to_s)[0...8]}" | |
params = { | |
"licenseRequest.firstName" => Faker::Name.first_name, | |
"licenseRequest.lastName" => Faker::Name.last_name, | |
"licenseRequest.registrationName" => Faker::Name.name, | |
"licenseRequest.email" => "#{login}@asdasd.ru", | |
"licenseRequest.company" => Faker::Company.name, | |
"licenseRequest.country" => "UNITED STATES", | |
"submitButton" => "Submit" | |
} | |
puts "post to #{jetbrains_uri}" | |
pp params | |
response = Net::HTTP.post_form(jetbrains_uri, params) | |
asdasd_inbox_uri = URI.parse("http://asdasd.ru/?to=#{login}&dfrom=jetbrains.com") | |
msgid = nil | |
while msgid.nil? | |
sleep_time = 60 | |
puts "sleep for #{sleep_time} seconds" | |
(sleep_time/10).times { sleep(10); print "." } | |
puts "\ncheck inbox #{asdasd_inbox_uri}" | |
inbox = Net::HTTP.get(asdasd_inbox_uri) | |
inbox =~ /location\.href='\/read\?msgid=(\d+)'/ | |
msgid = $1 | |
end | |
puts "message found msgid=#{msgid}" | |
asdasd_message_uri = URI.parse("http://asdasd.ru/read?msgid=#{msgid}") | |
puts "fetch message #{asdasd_message_uri}" | |
mail = Net::HTTP.get(asdasd_message_uri) | |
mail =~ /=+ LICENSE BEGIN =+(.*?)=+ LICENSE END =+/m | |
key = $1.gsub(/<br \/>/, "\n") | |
puts "Here your license key:" | |
puts key |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment