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

Commit

Permalink
Refactor interia
Browse files Browse the repository at this point in the history
  • Loading branch information
KonScanner committed Oct 15, 2023
1 parent 2acab08 commit 7f6e120
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 140 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
build|
dist"""

language_version: python3.9.7
language_version: python3.10

# flake8
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Faker==9.2.0
selenium==3.141.0
webdriver-manager==3.5.3
webdriver-manager
250 changes: 143 additions & 107 deletions sites/interia.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
from utils.Config import Config
from utils.Config import Config, SleepConfig
from selenium import webdriver
import time as t
import random
from utils.helper_functions import credential_creator, birthday_creator, write_if_complete
from utils.helper_functions import (
credential_creator,
birthday_creator,
write_if_complete,
)
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.support.ui import Select
import logging

logging.basicConfig(level=logging.INFO)

class Interia:

class Interia(Config):

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

def __init__(self):
Config.__init__(self)
SleepConfig.sleep_amount = 0.15
self.driver = webdriver.Chrome(
ChromeDriverManager().install(), options=Config(headless=False).options
)
self.failed_inputs = 0
self.driver.maximize_window()
self.e = None
(fullname, email, pwd) = credential_creator(fullname=False)
Expand All @@ -27,126 +36,153 @@ def __init__(self):
self.password = pwd
self.actions = ActionChains(self.driver)

def _try_click(self, x_path, css=False):
"""
Tries to click on the element with a timer (dirty solution).
@staticmethod
def sleeper(func):
def inner(*args, **kwargs):
result = func(*args, **kwargs)
t.sleep(SleepConfig.sleep_amount)
return result

:param x_path: x_path of element
:param css: True if css element path, False if x_path. Default: False
"""
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)
print(self.e)

def _select_month(self):
"""
Selects the month element and populates it.
"""
keytaps = "".join([".key_down(Keys.DOWN)" for _ in range(self.month)])
eval(f"self.actions{keytaps}.send_keys(Keys.ENTER).perform()")
return inner

def _select_clear(self):
"""
Selects the clear element.
"""
keytaps = "".join([".key_down(Keys.BACKSPACE)" for _ in range(100)])
eval(f"self.actions{keytaps}.perform()")
@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)

def _select_gender(self):
"""
Selects the gender of the email.
"""
keytaps = "".join(
[".key_down(Keys.DOWN)" for _ in range(random.randint(1, 2))]
@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)

eval(f"self.actions{keytaps}.send_keys(Keys.ENTER).perform()")
@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)

def _create(self):
"""
Creates the email.
"""
self.driver.get("https://konto-pocztowe.interia.pl/#/nowe-konto/darmowe")
t.sleep(0.55)
self._try_click("/html/body/div[3]/div[2]/button[3]")
# Pass in input
@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)

self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[1]/input"
).send_keys(self.first)
t.sleep(0.3)
self.driver.find_element_by_xpath(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[2]/input"
).send_keys(self.last)
t.sleep(0.3)
# Day of birth
self.driver.find_element_by_xpath(
@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"
).send_keys(self.day)
t.sleep(0.3)
# Day of month
self._try_click(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[3]/div[2]/div[2]"
)
self._select_month()
t.sleep(0.3)
# Day of Year
self.driver.find_element_by_xpath(
day.send_keys(self.day)

@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]"
)
self.force_click(dropdown)
options = self.driver.find_element_by_class_name("account-select__options")
first_item = options.find_element_by_class_name("account-select__options__item")
self.force_click(first_item)

@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"
).send_keys(self.year)
t.sleep(0.3)
self._try_click("/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[4]/div[2]")
self._select_gender()
username_tag = (
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[1]/div[5]/div[1]/input"
)
self.driver.find_element_by_xpath(username_tag).click()
self._select_clear()
t.sleep(0.3)
self.driver.find_element_by_xpath(username_tag).send_keys(self.username)
t.sleep(0.3)
year.send_keys(self.year)

self.driver.find_element_by_xpath(
@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"
).send_keys(self.password)
t.sleep(0.3)
)
pass_1.send_keys(self.password)

self.driver.find_element_by_xpath(
@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"
).send_keys(self.password)
t.sleep(0.3)
self._try_click(
"/html/body/div[1]/div/div/div/div/div[2]/div/form/div[2]/div[1]/div[1]/label"
)
t.sleep(0.3)
t.sleep(5)
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
pass_2.send_keys(self.password)

# Create account btn
self._try_click("/html/body/div[1]/div/div/div/div/div[2]/div/form/div[2]/button")
t.sleep(0.55)
self._try_click("/html/body/div[2]/div[3]/div/div[2]/div[1]")
self._try_click(
"/html/body/div[2]/section[3]/div[1]/div[1]/section/ul/li/div[2]/div[1]/div[1]/span"
def __deal_with_passwords(self):
self.__deal_with_pass1()
self.__deal_with_pass2()

@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]"
)
self.force_click(dropdown)
options = self.driver.find_element_by_class_name("account-select__options")
first_item = options.find_element_by_class_name("account-select__options__item")
self.force_click(first_item)

@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
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._try_click("/html/body/div[2]/section[4]/div/div/div[1]/div/div/span/div")
self._try_click("/html/body/div[2]/section[4]/div/div/div[2]/div/a[2]")
print("Was the account successfully created?")
response = input()
if response == "y":
self.force_click(conditions)
self.__remove_gambling_ads()

@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
def __account_created(self):
logging.warning("Has the account been created?")
s = input("[y/N]: ").lower()
if s == "y":
write_if_complete(
email=self.username, password=self.password, domain="interia", country="pl"
email=self.username,
password=self.password,
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!!!")

def _create(self):
"""
Creates the email.
"""
self.driver.get("https://konto-pocztowe.interia.pl/#/nowe-konto/darmowe")
t.sleep(0.55)
self.__deal_with_cookies()
self.__deal_with_name()
self.__deal_with_surname()
self.__deal_with_username()
self.__deal_with_day()
self.__deal_with_month()
self.__deal_with_year()
self.__deal_with_passwords()
self.__deal_with_gender()
self.__accept_bad_conditions()
self.__finalize_account_creation()
self.__account_created()
self.driver.quit()
Loading

0 comments on commit 7f6e120

Please sign in to comment.