Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'Capybara'
- $session = Capybara::Session.new(:selenium)
- class PopupAdError < StandardError
- end
- class EmailAlreadyExistsError < StandardError
- end
- class TimeExpiredError < StandardError
- end
- def generate_string
- o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
- return (0...10).map { o[rand(o.length)] }.join
- end
- def generate_email
- string = generate_string
- $session.visit('https://temp-mail.ru/option/change/');
- $session.find('input[name="mail"]').set(string)
- $session.click_button('postbut')
- return string + $session.find_by_id('domain').value
- end
- def fill_form(username, password, email)
- $session.fill_in('user_username', :with => username)
- $session.fill_in('user_email', :with => email)
- $session.fill_in('user_password', :with => password)
- $session.fill_in('user_password_confirmation', :with => password)
- $session.check('user_agreement')
- end
- def register_account(email)
- username = email[0..email.index('@') - 1]
- password = email[0..4].reverse! + '0' + email[0..4].upcase
- $session.visit('https://dev.by/registration')
- fill_form(username, password, email)
- $session.find('input[name="commit"]').click
- return [email, username, password]
- end
- def wait_for_confirmation_email
- $session.visit('https://temp-mail.ru/option/refresh')
- count = 0
- while (count < 60) && (!$session.has_text?('dev.by'))
- sleep 1
- count += 1
- end
- raise TimeExpiredError unless count < 60
- end
- def confirm_registration(email)
- wait_for_confirmation_email
- $session.click_link(class: 'title-subject')
- $session.click_link('подтвердить')
- sleep 3
- $session.driver.quit
- end
- def create_account
- begin
- email = generate_email
- account = register_account(email)
- confirm_registration(account[0])
- puts account[1].to_s + "\t" + account[2].to_s
- return 1
- rescue PopupAdError
- # No idea how to close tab in capybara :(
- return 0
- rescue EmailAlreadyExistsError
- #
- puts '[this email already exists]'
- return 0
- rescue TimeExpiredError
- #
- puts '[time limit has expired]'
- return 0
- end
- end
- require 'Capybara'
- $session = Capybara::Session.new(:selenium)
- class PopupAdError < StandardError
- end
- class EmailAlreadyExistsError < StandardError
- end
- class TimeExpiredError < StandardError
- end
- def generate_string
- o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
- return (0...10).map { o[rand(o.length)] }.join
- end
- def generate_email
- string = generate_string
- $session.visit('https://temp-mail.ru/option/change/');
- $session.find('input[name="mail"]').set(string)
- $session.click_button('postbut')
- return string + $session.find_by_id('domain').value
- end
- def fill_form(username, password, email)
- $session.fill_in('user_username', :with => username)
- $session.fill_in('user_email', :with => email)
- $session.fill_in('user_password', :with => password)
- $session.fill_in('user_password_confirmation', :with => password)
- $session.check('user_agreement')
- end
- def register_account(email)
- username = email[0..email.index('@') - 1]
- password = email[0..4].reverse! + '0' + email[0..4].upcase
- $session.visit('https://dev.by/registration')
- fill_form(username, password, email)
- $session.find('input[name="commit"]').click
- return [email, username, password]
- end
- def wait_for_confirmation_email
- $session.visit('https://temp-mail.ru/option/refresh')
- count = 0
- while (count < 60) && (!$session.has_text?('dev.by'))
- sleep 1
- count += 1
- end
- raise TimeExpiredError unless count < 60
- end
- def confirm_registration(email)
- wait_for_confirmation_email
- $session.click_link(class: 'title-subject')
- $session.click_link('подтвердить')
- sleep 3
- $session.driver.quit
- end
- def create_account
- begin
- email = generate_email
- account = register_account(email)
- confirm_registration(account[0])
- puts account[1].to_s + "\t" + account[2].to_s
- return 1
- rescue PopupAdError
- # No idea how to close tab in capybara :(
- return 0
- rescue EmailAlreadyExistsError
- #
- puts '[this email already exists]'
- return 0
- rescue TimeExpiredError
- #
- puts '[time limit has expired]'
- return 0
- end
- end
- def run(amount)
- number_of_accounts = 0
- puts 'created accounts:'
- while number_of_accounts < amount
- number_of_accounts += create_account
- end
- end
- #run(ARGV[0].to_i)
- run(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement