Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 4.40 KB | None | 0 0
  1. require 'Capybara'
  2.  
  3. $session = Capybara::Session.new(:selenium)
  4.  
  5. class PopupAdError < StandardError
  6. end
  7.  
  8. class EmailAlreadyExistsError < StandardError
  9. end
  10.  
  11. class TimeExpiredError < StandardError
  12. end
  13.  
  14. def generate_string
  15.   o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
  16.   return (0...10).map { o[rand(o.length)] }.join
  17. end
  18.  
  19. def generate_email
  20.   string = generate_string
  21.   $session.visit('https://temp-mail.ru/option/change/');
  22.   $session.find('input[name="mail"]').set(string)
  23.   $session.click_button('postbut')
  24.   return string + $session.find_by_id('domain').value
  25. end
  26.  
  27. def fill_form(username, password, email)
  28.   $session.fill_in('user_username', :with => username)
  29.   $session.fill_in('user_email', :with => email)
  30.   $session.fill_in('user_password', :with => password)
  31.   $session.fill_in('user_password_confirmation', :with => password)
  32.   $session.check('user_agreement')
  33. end
  34.  
  35. def register_account(email)
  36.   username = email[0..email.index('@') - 1]
  37.   password = email[0..4].reverse! + '0' + email[0..4].upcase
  38.   $session.visit('https://dev.by/registration')
  39.   fill_form(username, password, email)
  40.   $session.find('input[name="commit"]').click
  41.   return [email, username, password]
  42. end
  43.  
  44. def wait_for_confirmation_email
  45.   $session.visit('https://temp-mail.ru/option/refresh')
  46.   count = 0
  47.   while (count < 60) && (!$session.has_text?('dev.by'))
  48.     sleep 1
  49.     count += 1
  50.   end
  51.   raise TimeExpiredError unless count < 60
  52. end
  53.  
  54. def confirm_registration(email)
  55.   wait_for_confirmation_email
  56.   $session.click_link(class: 'title-subject')
  57.   $session.click_link('подтвердить')
  58.   sleep 3
  59.   $session.driver.quit
  60. end
  61.  
  62. def create_account
  63.   begin
  64.     email = generate_email
  65.     account = register_account(email)
  66.     confirm_registration(account[0])
  67.     puts account[1].to_s + "\t" + account[2].to_s
  68.     return 1
  69.   rescue PopupAdError
  70.     # No idea how to close tab in capybara :(
  71.     return 0
  72.   rescue EmailAlreadyExistsError
  73.     #
  74.     puts '[this email already exists]'
  75.     return 0
  76.   rescue TimeExpiredError
  77.     #
  78.     puts '[time limit has expired]'
  79.     return 0
  80.   end
  81. end
  82.  
  83. require 'Capybara'
  84.  
  85. $session = Capybara::Session.new(:selenium)
  86.  
  87. class PopupAdError < StandardError
  88. end
  89.  
  90. class EmailAlreadyExistsError < StandardError
  91. end
  92.  
  93. class TimeExpiredError < StandardError
  94. end
  95.  
  96. def generate_string
  97.   o = [('a'..'z'), ('0'..'9')].map(&:to_a).flatten
  98.   return (0...10).map { o[rand(o.length)] }.join
  99. end
  100.  
  101. def generate_email
  102.   string = generate_string
  103.   $session.visit('https://temp-mail.ru/option/change/');
  104.   $session.find('input[name="mail"]').set(string)
  105.   $session.click_button('postbut')
  106.   return string + $session.find_by_id('domain').value
  107. end
  108.  
  109. def fill_form(username, password, email)
  110.   $session.fill_in('user_username', :with => username)
  111.   $session.fill_in('user_email', :with => email)
  112.   $session.fill_in('user_password', :with => password)
  113.   $session.fill_in('user_password_confirmation', :with => password)
  114.   $session.check('user_agreement')
  115. end
  116.  
  117. def register_account(email)
  118.   username = email[0..email.index('@') - 1]
  119.   password = email[0..4].reverse! + '0' + email[0..4].upcase
  120.   $session.visit('https://dev.by/registration')
  121.   fill_form(username, password, email)
  122.   $session.find('input[name="commit"]').click
  123.   return [email, username, password]
  124. end
  125.  
  126. def wait_for_confirmation_email
  127.   $session.visit('https://temp-mail.ru/option/refresh')
  128.   count = 0
  129.   while (count < 60) && (!$session.has_text?('dev.by'))
  130.     sleep 1
  131.     count += 1
  132.   end
  133.   raise TimeExpiredError unless count < 60
  134. end
  135.  
  136. def confirm_registration(email)
  137.   wait_for_confirmation_email
  138.   $session.click_link(class: 'title-subject')
  139.   $session.click_link('подтвердить')
  140.   sleep 3
  141.   $session.driver.quit
  142. end
  143.  
  144. def create_account
  145.   begin
  146.     email = generate_email
  147.     account = register_account(email)
  148.     confirm_registration(account[0])
  149.     puts account[1].to_s + "\t" + account[2].to_s
  150.     return 1
  151.   rescue PopupAdError
  152.     # No idea how to close tab in capybara :(
  153.     return 0
  154.   rescue EmailAlreadyExistsError
  155.     #
  156.     puts '[this email already exists]'
  157.     return 0
  158.   rescue TimeExpiredError
  159.     #
  160.     puts '[time limit has expired]'
  161.     return 0
  162.   end
  163. end
  164.  
  165. def run(amount)
  166.   number_of_accounts = 0
  167.   puts 'created accounts:'
  168.   while number_of_accounts < amount
  169.     number_of_accounts += create_account
  170.   end
  171. end
  172.  
  173. #run(ARGV[0].to_i)
  174. run(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement