Guest User

Untitled

a guest
Jul 25th, 2021
6,148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. from selenium import webdriver
  3. from selenium.webdriver.common.action_chains import ActionChains
  4. import datetime
  5. import smtplib
  6. import time
  7. import imaplib
  8. import email
  9. import traceback
  10.  
  11. FROM_EMAIL = "********@gmail.com"
  12. FROM_PWD = "********"
  13. SMTP_SERVER = "imap.gmail.com"
  14. SMTP_PORT = 993
  15.  
  16. chromedriver_path = "X:\\chromedriver.exe"
  17.  
  18. def format_td(seconds, digits=2):
  19.     isec, fsec = divmod(round(seconds*10**digits), 10**digits)
  20.     return ("{}.{:0%d.0f}" % digits).format(datetime.timedelta(seconds=isec), fsec)
  21.  
  22.  
  23. def de_accentize(string):
  24.     character_pairs = {"á" : "a", "é" : "e", "í" : "i", "ó" : "o", "ö" : "o", "ő" : "o", "ú" : "u", "ü" : "u", "ű" : "u"}
  25.    
  26.     for character in character_pairs:
  27.         if character in string:
  28.             string = string.replace(character, character_pairs[character])
  29.         elif character.upper() in string:
  30.             string = string.replace(character.upper(), character_pairs[character].upper())
  31.    
  32.     return string
  33.  
  34. class Person:
  35.     def __init__(self, person_id):
  36.         self.id = person_id
  37.         self.name = self.generate_random_name()
  38.         self.age = random.randint(18,85)
  39.         self.email = "orbanegyg3ci+" + str(self.id).zfill(5) + de_accentize(self.family_name.lower() + "." + de_accentize(self.first_name.lower().replace(" ", "."))) + "_" + str(self.age) + "@gmail.com"
  40.  
  41.     def generate_random_name(self, double_name_percentage = 5):
  42.         family_names = ["NAGY","KOVÁCS","TÓTH","SZABÓ","HORVÁTH","VARGA","KISS","MOLNÁR","NÉMETH","FARKAS","BALOGH","PAPP","LAKATOS","TAKÁCS","JUHÁSZ","OLÁH","MÉSZÁROS","SIMON","RÁCZ","FEKETE","SZILÁGYI","TÖRÖK","FEHÉR","BALÁZS","GÁL","KIS","SZŰCS","ORSÓS","KOCSIS","FODOR","PINTÉR","SZALAI","SIPOS","MAGYAR","LUKÁCS","GULYÁS","BIRÓ","KIRÁLY","BALOG","LÁSZLÓ","BOGDÁN","JAKAB","KATONA","SÁNDOR","VÁRADI","BOROS","FAZEKAS","KELEMEN","ANTAL","OROSZ","SOMOGYI","FÜLÖP","VERES","BUDAI","VINCZE","HEGEDŰS","DEÁK","PAP","BÁLINT","ILLÉS","PÁL","VASS","SZŐKE","FÁBIÁN","VÖRÖS","LENGYEL","BOGNÁR","BODNÁR","JÓNÁS","SZÜCS","HAJDU","HALÁSZ","MÁTÉ","SZÉKELY","GÁSPÁR","KOZMA","PÁSZTOR","BAKOS","DUDÁS","VIRÁG","MAJOR","ORBÁN","HEGEDÜS","BARNA","NOVÁK","SOÓS","TAMÁS","NEMES","PATAKI","BALLA","FARAGÓ","KEREKES","BARTA","PÉTER","BORBÉLY","CSONKA","MEZEI","SÁRKÖZI","BERKI","MÁRTON"]
  43.         first_names = [
  44.                 ["Gábor","László","Attila","Péter","Tamás","István","Zsolt","József","János","Csaba","Sándor","Róbert","Krisztián","Ferenc","András","Balázs","Tibor","Norbert","Szabolcs","Imre","György","Gergely","Lajos","Roland","Viktor","Gyula","Károly","Miklós","Mihály","Béla","Dániel","Ákos","Ádám","Richárd","Árpád","Dávid","Pál","Szilárd","Antal","Bálint","Levente","Márton","Géza","Kornél","Gergő","Kálmán","Endre","Nándor","Máté","Barnabás","Dénes","Jenő","Márk","Ernő","Mátyás","Ottó","Dezső","Bence","Vilmos","Ervin","Áron","Arnold","Olivér","Bertalan","Rudolf","Milán","Albert","Lóránt","Szilveszter","Andor","Kristóf","Barna","Győző","Henrik","Iván","Adrián","Erik","Jácint","Gusztáv"],
  45.                 ["Krisztina","Katalin","Mónika","Szilvia","Anita","Zsuzsanna","Éva","Judit","Ágnes","Tímea","Erika","Ildikó","Mária","Anikó","Melinda","Gabriella","Eszter","Beáta","Erzsébet","Viktória","Tünde","Edina","Adrienn","Bernadett","Rita","Edit","Orsolya","Hajnalka","Csilla","Renáta","Brigitta","Annamária","Veronika","Nikoletta","Marianna","Enikő","Ilona","Anna","Dóra","Nóra","Márta","Mariann","Barbara","Anett","Henrietta","Beatrix","Ibolya","Zsófia","Emese","Noémi","Zita","Réka","Nikolett","Gyöngyi","Kinga","Diána","Julianna","Zsanett","Zsuzsa","Magdolna","Klára","Margit","Lívia","Angéla","Petra","Piroska","Boglárka","Henriett","Alexandra","Irén","Szabina","Helga","Timea","Klaudia","Ivett","Izabella","Valéria","Júlia"]]
  46.    
  47.         rnd = random.randint(0,100)
  48.         gender = random.randint(0,1) # A GENDER VESZÉLYES!!!!!!4 STOP SOROS
  49.    
  50.         if rnd < double_name_percentage:
  51.             names = 2
  52.         else:
  53.             names = 1
  54.    
  55.         self.family_name = family_names[random.randint(0, len(family_names)-1)].lower().capitalize()
  56.        
  57.         self.first_name = ""
  58.    
  59.         for n in range(names):
  60.             selected_name = first_names[gender][random.randint(0,len(first_names[gender])-1)]
  61.             if self.first_name == "":
  62.                 self.first_name = selected_name
  63.             else:
  64.                 self.first_name = self.first_name + " " + selected_name
  65.  
  66.     def register(self):
  67.         driver.get("https://nemzetikonzultacio.kormany.hu/")
  68.         family_name_input = driver.find_element_by_id("mat-input-0")
  69.         family_name_input.send_keys(self.family_name)
  70.         time.sleep(.1)
  71.         first_name_input = driver.find_element_by_id("mat-input-1")
  72.         first_name_input.send_keys(self.first_name)
  73.         time.sleep(.1)
  74.         # age_input = driver.find_element_by_xpath("//*[@class='small-input ng-pristine ng-invalid ng-touched']")
  75.         age_input = driver.find_element_by_xpath("//input[@placeholder='Életkor * (kötelező)']")
  76.         age_input.send_keys(self.age)
  77.         time.sleep(.1)
  78.         email_input = driver.find_element_by_id("mat-input-2")
  79.         email_input.send_keys(self.email)
  80.  
  81.         driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  82.        
  83.         cboxes = driver.find_elements_by_class_name("mat-checkbox-inner-container")
  84.         for cbox in cboxes:
  85.             cbox.click()
  86.             time.sleep(.1)
  87.  
  88.         '''
  89.         hun_checkbox = driver.find_element_by_id("mat-checkbox-1-input")
  90.         hun_checkbox.click()
  91.         time.sleep(.1)
  92.         cbox_2 = driver.find_element_by_id("mat-checkbox-2-input")
  93.         cbox_2.click()
  94.         time.sleep(.1)
  95.         buttons = driver.find_elements_by_css_selector("input[type='button']")
  96.         '''
  97.  
  98.         reg_button = driver.find_element_by_xpath("//*[@class='btn w-auto']")
  99.         reg_button.click()
  100.  
  101.     def check_email(self):
  102.         email_received = False
  103.        
  104.         while email_received == False:
  105.             print(".", end="", flush=True)
  106.             try:
  107.                 mail = imaplib.IMAP4_SSL(SMTP_SERVER)
  108.                 mail.login(FROM_EMAIL,FROM_PWD)
  109.                 mail.select('inbox')
  110.        
  111.                 data = mail.search(None, 'ALL')
  112.                 mail_ids = data[1]
  113.                 id_list = mail_ids[0].split()  
  114.                 first_email_id = int(id_list[0])
  115.                 latest_email_id = int(id_list[-1])
  116.        
  117.                 # for i in range(latest_email_id,first_email_id, -1):
  118.        
  119.                 for i in range(latest_email_id,latest_email_id-1, -1):
  120.                     data = mail.fetch(str(i), '(RFC822)' )
  121.                     for response_part in data:
  122.                         arr = response_part[0]
  123.                         if isinstance(arr, tuple):
  124.                             msg = email.message_from_string(str(arr[1],'utf-8'))
  125.                             to = msg["Delivered-To"]
  126.  
  127.                             if to == self.email:
  128.  
  129.                                 email_subject = msg['subject']
  130.                                 email_from = msg['from']
  131.                                 # print('From : ' + email_from + '\n')
  132.                                 # print('Subject : ' + email_subject + '\n')
  133.                                 # print(msg["Delivered-To"])
  134.                                 # print(msg._payload[0].__dict__)
  135.                                 part_list = list(msg._payload[1]._payload.split("<"))
  136.                                 for counter, part in enumerate(part_list):
  137.                                     if "a href" in part:
  138.                                         url, junk = part.split('" target=3D"_blank"')
  139.                                         url = url.replace('a href=3D"', "")
  140.                                         url = url.replace("\r", "").replace("\n", "").replace("konzulta=cio", "konzultacio")
  141.                                        
  142.                                         self.custom_url = url
  143.  
  144.                                 email_received = True
  145.        
  146.             except Exception as e:
  147.                 traceback.print_exc()
  148.                 print(str(e))
  149.  
  150.             time.sleep(.25)
  151.  
  152.     def fill_form(self):
  153.         actions = ActionChains(driver)
  154.         driver.get(self.custom_url)
  155.  
  156.         time.sleep(.5)
  157.        
  158.         radio_buttons = driver.find_elements_by_css_selector("input[type='radio']")
  159.  
  160.         # radio_buttons = driver.find_elements_by_class_name("mat-radio-label")
  161.  
  162.  
  163.         fill_pattern = list()
  164.         fill_pattern_check = list()
  165.         counter = 0
  166.  
  167.         for x in range(14):
  168.             select = random.randint(0,1)
  169.             fill_pattern.append(counter+select)
  170.             fill_pattern_check.append(select)
  171.             counter += 2
  172.  
  173.         # print("fill pattern", fill_pattern)
  174.         # print("fill pattern check", fill_pattern_check)
  175.  
  176.  
  177.  
  178.         for counter, rb in enumerate(radio_buttons):
  179.             # actions.move_to_element(rb).perform()
  180.             driver.execute_script("return arguments[0].scrollIntoView(true);", rb)
  181.            
  182.             if counter in fill_pattern:
  183.             # if 1 == 1:
  184.                 driver.execute_script("arguments[0].click();", rb)
  185.                 time.sleep(.05)
  186.             else:
  187.                 pass
  188.  
  189.  
  190.         reg_button = driver.find_element_by_xpath("//*[@class='btn submit-btn']")
  191.         driver.execute_script("arguments[0].click();", reg_button)
  192.                
  193.  
  194.  
  195. if __name__ == "__main__":
  196.     driver = webdriver.Chrome(chromedriver_path)
  197.     start_time = datetime.datetime.now()
  198.    
  199.     for x in range(100000):
  200.  
  201.         if x % 10 == 0:
  202.             print("================================================================================\n                                    -= NERbot 2.0 =-                  \nDISCLAIMER: a robot egy átlagos Fideszesnél is butább (talán még Hollik Istvánnál is,\n      de ez nem biztos) és csak véletlenszerű válaszokat ad az egyes kérdésekre.\n      A KÉRDÉSEKRE ADOTT VÁLASZOK NEM TÜKRÖZIK A ROBOT FEJLESZTŐJÉNEK ÁLLÁSPONTJÁT,\n     A NERBOT KIZÁRÓLAGOS CÉLJA A KORMÁNYZATI INFORMATIKA SZÍNVONALÁNAK DEMONSTRÁLÁSA\n================================================================================\n")
  203.        
  204.         person = Person(person_id = x)
  205.         person.start_time = datetime.datetime.now()
  206.        
  207.         print("{} vagyok, {} éves, a(z) {}. sorszámú NER-birka.\nRegisztrálok a(z) {} e-mailcímmel...".format(person.family_name + " " + person.first_name, person.age, person.id, person.email))
  208.    
  209.         person.register()
  210.    
  211.         print("Regisztráció megtörtént, várom az e-mailt")
  212.    
  213.         person.check_email()
  214.    
  215.         print("Megjött! Nyomás kitölteni: " + person.custom_url)
  216.    
  217.         person.fill_form()
  218.    
  219.         person.end_time = datetime.datetime.now()
  220.    
  221.         person.time = person.end_time - person.start_time
  222.         person.seconds = format_td(person.time.seconds, digits=2)
  223.  
  224.         # person.time = person.time.strftime("%S") + "," + person.time.strftime("%f")[:2]
  225.         total_time = datetime.datetime.now() - start_time
  226.    
  227.         print("Konzultáció kitöltve, {} másodpercig tartott, összes eltelt idő: {}\n".format(person.seconds, total_time))
  228.  
  229.         time.sleep(1)
  230.  
  231.     driver.quit()
  232.  
  233.  
  234.  
  235.  
RAW Paste Data