Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
Refactor TutaNota + add support functions on load
Browse files Browse the repository at this point in the history
  • Loading branch information
KonScanner committed Oct 15, 2023
1 parent 947c730 commit 0dbc823
Show file tree
Hide file tree
Showing 3 changed files with 181 additions and 108 deletions.
42 changes: 15 additions & 27 deletions sites/interia.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
write_if_complete,
safe_split,
)
from selenium.webdriver.common.action_chains import ActionChains
from webdriver_manager.chrome import ChromeDriverManager
import logging

Expand All @@ -28,57 +27,46 @@ def __init__(self):
)
self.failed_inputs = 0
self.driver.maximize_window()
self.e = None
(fullname, email, pwd) = credential_creator(fullname=False)
self.first, self.last = safe_split(fullname)
self.day, self.month, self.year = birthday_creator()
self.username = email
self.password = pwd
self.actions = ActionChains(self.driver)

@staticmethod
def sleeper(func):
def inner(*args, **kwargs):
result = func(*args, **kwargs)
t.sleep(SleepConfig.sleep_amount)
return result

return inner

@sleeper
@Config.sleeper
def __deal_with_cookies(self):
cookies = self.driver.find_element_by_xpath("/html/body/div[3]/div[2]/button[3]")
self.force_click(cookies)

@sleeper
@Config.sleeper
def __deal_with_name(self):
name = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[1]/input"
)
name.send_keys(self.first)

@sleeper
@Config.sleeper
def __deal_with_surname(self):
surname = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[2]/input"
)
surname.send_keys(self.last)

@sleeper
@Config.sleeper
def __deal_with_username(self):
username = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[5]/div[1]/input"
)
username.send_keys(self.username)

@sleeper
@Config.sleeper
def __deal_with_day(self):
day = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[3]/div[1]/input"
)
day.send_keys(self.day)

@sleeper
@Config.sleeper
def __deal_with_month(self):
dropdown = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[3]/div[2]"
Expand All @@ -88,21 +76,21 @@ def __deal_with_month(self):
first_item = options.find_element_by_class_name("account-select__options__item")
self.force_click(first_item)

@sleeper
@Config.sleeper
def __deal_with_year(self):
year = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[3]/div[3]/input"
)
year.send_keys(self.year)

@sleeper
@Config.sleeper
def __deal_with_pass1(self):
pass_1 = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[6]/div/input"
)
pass_1.send_keys(self.password)

@sleeper
@Config.sleeper
def __deal_with_pass2(self):
pass_2 = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[7]/div/input"
Expand All @@ -113,7 +101,7 @@ def __deal_with_passwords(self):
self.__deal_with_pass1()
self.__deal_with_pass2()

@sleeper
@Config.sleeper
def __deal_with_gender(self):
dropdown = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[4]/div[1]"
Expand All @@ -123,30 +111,30 @@ def __deal_with_gender(self):
first_item = options.find_element_by_class_name("account-select__options__item")
self.force_click(first_item)

@sleeper
@Config.sleeper
def __remove_gambling_ads(self):
gambling_ads = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[2]/div[1]/div[2]/div[4]/label"
)
self.force_click(gambling_ads)

@sleeper
@Config.sleeper
def __accept_bad_conditions(self):
conditions = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[2]/div[1]/div[1]/label/div/div"
)
self.force_click(conditions)
self.__remove_gambling_ads()

@sleeper
@Config.sleeper
def __finalize_account_creation(self):
create_account = self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[2]/button"
)
self.force_click(create_account)
t.sleep(2)

@sleeper
@Config.sleeper
def __account_created(self):
logging.warning("Has the account been created?")
s = input("[y/N]: ").lower()
Expand All @@ -172,7 +160,7 @@ def _create(self):
Creates the email.
"""
self.driver.get("https://konto-pocztowe.interia.pl/#/nowe-konto/darmowe")
t.sleep(0.55)
t.sleep(1)
self.__deal_with_cookies()
self.__deal_with_name()
self.__deal_with_surname()
Expand Down
205 changes: 125 additions & 80 deletions sites/tutanota.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from utils.Config import Config
from utils.Config import Config, SleepConfig
from selenium import webdriver
import time as t
from utils.helper_functions import credential_creator, write_if_complete
Expand All @@ -8,116 +8,161 @@
logging.basicConfig(level=logging.INFO)


class TutaAccounts:
class TutaAccounts(Config):

"""
This function is used to register a new email on the TutaNota website.
"""

def __init__(self):
Config.__init__(self)
SleepConfig.sleep_amount = 0.15
self.recovery = True
self.driver = webdriver.Chrome(
ChromeDriverManager().install(), options=Config(headless=False).options
)
self.failed_inputs = 0
self.driver.maximize_window()
self.e = None
(_, email, pwd) = credential_creator(fullname=False)
self.username = email
self.password = pwd

def _try_click(self, x_path, css=False, prompt=""):
"""
Tries to click on the element with a timer (dirty solution).
:param x_path: x_path of element
:param css: True if css element path, False if x_path. Default: False
"""
if prompt != "":
logging.info(f"[ACTION]: {prompt}")
state = True
for _ in range(6):
if state:
try:
if not css:
self.driver.find_element_by_xpath(x_path).click()
else:
self.driver.find_element_by_css_selector(x_path).click()
t.sleep(1)
state = False
print(state)
except Exception as e:
self.e = e
t.sleep(1.5)
logging.error(f"Failed to click with exception {self.e}")

def _create(self):
"""
Creates the email.
"""
# Load site
self.driver.get("https://mail.tutanota.com/login")
@Config.sleeper
def __account_created(self, recovery_key: str = ""):
logging.warning("Has the account been created?")
s = input("[y/N]: ").lower()
if s == "y":
t.sleep(3)
if self.recovery:
recovery_key = self.__save_recovery()
write_if_complete(
email=self.username,
password=f"{self.password}:{recovery_key}",
domain="interia",
country="pl",
)
elif s == "n":
self.failed_inputs += 1
logging.error("Account was not successfully created, please try again.")
else:
logging.error("The answer provided is not y or n! PLEASE INSERT CORRECT ANSWER...")
if self.failed_inputs < 3:
self.__account_created()
else:
raise ValueError("The answer provided was not y or n!!!")

# Click Sign-up
self._try_click(
"/html/body/div/div[3]/div[2]/div/div[1]/div[2]/button[1]/div/div",
prompt="Click Sign-up",
@Config.sleeper
def __select_signup(self):
signup = self.force_find(
driver=self.driver,
element_str="/html/body/div/div[3]/div[2]/div/div[1]/div[2]/button[1]/div/div",
search_type="xpath",
)
self.force_click(signup)
t.sleep(4)

# Free version
self._try_click(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[3]/div[1]/div/div[1]/div[5]/button/div"
@Config.sleeper
def __select_free_version(self):
free_version = self.force_find(
driver=self.driver,
element_str="/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[3]/div[1]/div/div[1]/div[5]/button/div",
search_type="xpath",
)
self.force_click(free_version)

# Checkboxes
self._try_click(
"#modal > div:nth-child(2) > div > div > div > div:nth-child(2) > div:nth-child(1) >"
" div > input[type=checkbox]",
css=True,
)
self._try_click(
"#modal > div:nth-child(2) > div > div > div > div:nth-child(2) > div:nth-child(2) >"
" div > input[type=checkbox]",
css=True,
@Config.sleeper
def __select_checkboxes(self):
checkboxes = [
self.driver.find_element_by_css_selector(
"#modal > div:nth-child(2) > div > div > div > div:nth-child(2) > div:nth-child(1) >"
" div > input[type=checkbox]"
)
]
checkboxes.append(
self.driver.find_element_by_css_selector(
"#modal > div:nth-child(2) > div > div > div > div:nth-child(2) > div:nth-child(2) >"
" div > input[type=checkbox]"
)
)
t.sleep(0.15)
self._try_click(
"#modal > div:nth-child(2) > div > div > div > div.flex-center.dialog-buttons >"
" button:nth-child(2)",
css=True,
checkboxes.append(
self.driver.find_element_by_css_selector(
"#modal > div:nth-child(2) > div > div > div > div.flex-center.dialog-buttons >"
" button:nth-child(2)"
)
)
t.sleep(0.55)
# Pass in input
for item in checkboxes:
self.force_click(item)
t.sleep(3)

# Pass in username
self.driver.find_element_by_css_selector(
@Config.sleeper
def __deal_with_username(self):
username = self.driver.find_element_by_css_selector(
"#signup-account-dialog > div > div.text-field.rel.overflow-hidden.text.pt > div > div"
" > div > div.flex-grow.rel > input"
).send_keys(self.username)
t.sleep(0.15)
)
username.send_keys(self.username)

# Pass in password
self.driver.find_element_by_css_selector(
@Config.sleeper
def __deal_with_password_1(self):
pass_1 = self.driver.find_element_by_css_selector(
"#signup-account-dialog > div > div:nth-child(2) > div:nth-child(1) > div > div > div >"
" div.flex-grow.rel > input.input"
).send_keys(self.password)
t.sleep(0.15)
)
pass_1.send_keys(self.password)

# Pass in repeat password
self.driver.find_element_by_css_selector(
@Config.sleeper
def __deal_with_password_2(self):
pass_2 = self.driver.find_element_by_css_selector(
"#signup-account-dialog > div > div:nth-child(2) > div:nth-child(2) > div > div > div > div.flex-grow.rel > input"
).send_keys(self.password)
t.sleep(0.15)
self._try_click(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[3]/div/input"
)
self._try_click(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[4]/div/input"
pass_2.send_keys(self.password)

def __deal_with_passwords(self):
self.__deal_with_password_1()
self.__deal_with_password_2()

@Config.sleeper
def __deal_with_final_checkboxes(self):
checkboxes = [
self.driver.find_element_by_xpath(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[3]/div/input"
)
]
checkboxes.append(
self.driver.find_element_by_xpath(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[4]/div/input"
)
)
for item in checkboxes:
self.force_click(item)

def __finalize_account_creation(self):
create_account = self.driver.find_element_by_xpath(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[5]/button/div"
)
t.sleep(4)
self._try_click(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[2]/div/div[5]/button"
self.force_click(create_account)

def __save_recovery(self):
return (
self.driver.find_element_by_xpath(
"/html/body/div/div[2]/div/div/div/div/div/div[2]/div/div/div[3]/div[2]"
)
.text.strip("")
.replace("\n", "")
)
response = input("Was the account successfully created? [y/n] ")

if response.lower() == "y":
write_if_complete(email=self.username, password=self.password, domain="tutanota")
def _create(self):
"""
Creates the email.
"""
self.driver.get("https://mail.tutanota.com/login")
t.sleep(1)
self.__select_signup()
self.__select_free_version()
self.__select_checkboxes()
self.__deal_with_username()
self.__deal_with_passwords()
self.__deal_with_final_checkboxes()
self.__finalize_account_creation()
self.__account_created()
self.driver.quit()
Loading

0 comments on commit 0dbc823

Please sign in to comment.