Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicbyte authored Aug 25, 2023
2 parents 12a9bd2 + 4d92dbb commit 61e1e3b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 24 deletions.
2 changes: 1 addition & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
DRIVER_TIMEOUT_S = 120 # int, float
MICRO_DELAY_S = 1 # int, float
HIDE_BROWSER = False
MAX_RETRIES = 3 # Max retries for creating/protecting account
MAX_RETRIES = 10 # Max retries for creating/protecting account
# You can set to False if you have Firefox installed
BUILTIN_DRIVER = False
LOG_LEVEL = 'DEBUG' # DEBUG, INFO, WARNING, ERROR, CRITICAL
Expand Down
24 changes: 13 additions & 11 deletions create_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

try:
import coloredlogs
coloredlogs.install(level='DEBUG', fmt='%(asctime)s %(levelname)s %(message)s')
coloredlogs.install(level=LOG_LEVEL, fmt='%(asctime)s %(levelname)s %(message)s')
except ImportError:
logging.basicConfig(level='DEBUG')
logging.basicConfig(level=LOG_LEVEL)
logging.warning('Coloredlogs is not installed. Install it with "pip install coloredlogs" to get cool logs!')

# Set config variables
Expand Down Expand Up @@ -80,12 +80,12 @@ def save_account(email: str, username: str, password: str):
# Create accounts
for i in range(num_of_accounts):
proxy_ = proxy.get_next()
retries = MAX_RETRIES
retries = 0

_logger.info('Creating account (%s/%s)', i+1, num_of_accounts)
_logger.info('Using proxy: %s', proxy)

while True:
while retries < MAX_RETRIES:
try:
email, username, password = create_account(
email=EMAIL or None,
Expand All @@ -97,11 +97,13 @@ def save_account(email: str, username: str, password: str):
except UsernameTakenException:
_logger.error('Username %s taken. Trying again.', username)

except SessionExpiredException:
_logger.error('Page session expired. Trying again.')

except NetworkException as e:
# If we are using local IP address, we can't bypass IP cooldown
if isinstance(proxy, EmptyProxy) and (
isinstance(e, IPCooldownException) or
isinstance(e, EMailCooldownException)):
isinstance(e, IPCooldownException)):
_logger.error(e)
_logger.error('IP cooldown. Try again later or use tor/proxies.')
exit(0)
Expand All @@ -116,12 +118,12 @@ def save_account(email: str, username: str, password: str):

except WebDriverException as e:
_logger.error(e)
retries -= 1
if retries <= 0:
_logger.error('An error occurred during account creation. Exiting...')
exit(1)
logging.error('An error occurred during account creation. Trying again %s more times...', retries)
logging.error('An error occurred during account creation. Trying again %s more times...', MAX_RETRIES - retries)
retries += 1
username, password = None, None
else:
_logger.error('An error occurred during account creation. Exiting...')
exit(1)

save_account(email, username, password)
_logger.info('Account created! Protecting account...')
Expand Down
15 changes: 14 additions & 1 deletion reddit_account_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
import static_ffmpeg
import logging as _logging
_logger = _logging.getLogger(__name__)

# Download necessary ffmpeg binary
_logger.info('Downloading ffmpeg binary...')
static_ffmpeg.add_paths()
del static_ffmpeg

from .maker import create_account
from .protector import protect_account
from .verifier import verify_email


def install_driver():
"""Install firefox driver binary."""
import webdriverdownloader
webdriverdownloader.GeckoDriverDownloader().download_and_install()
try:
webdriverdownloader.GeckoDriverDownloader().download_and_install()
except RuntimeError:
raise RuntimeError('Failed to install firefox driver. You\'re probably running the application too many times. Try again later. Limit: 60 requests per hour')
2 changes: 1 addition & 1 deletion reddit_account_generator/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.3.0'
__version__ = '1.2.0'
2 changes: 1 addition & 1 deletion reddit_account_generator/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PasswordLengthException(Exception):
class IPCooldownException(Exception):
pass

class EMailCooldownException(Exception):
class SessionExpiredException(Exception):
pass

class IncorrectUsernameOrPasswordException(Exception):
Expand Down
23 changes: 19 additions & 4 deletions reddit_account_generator/maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import logging

from tempmail import EMail
from selenium.common.exceptions import TimeoutException, WebDriverException, NoSuchElementException
from selenium.common.exceptions import TimeoutException, WebDriverException, NoSuchElementException, ElementClickInterceptedException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium_recaptcha_solver import RecaptchaSolver
from selenium_recaptcha_solver import RecaptchaSolver, RecaptchaException

from .utils import setup_firefox_driver, try_to_click, generate_password, generate_username
from .exceptions import *
Expand Down Expand Up @@ -43,6 +43,14 @@ def create_account(email: str | None = None, username: str | None = None, passwo
except WebDriverException:
raise TimeoutException('Website takes too long to load. Probably a problem with the proxy.')

# Checking if IP is blocked
try:
first_h1 = driver.find_element(By.TAG_NAME, 'h1')
if first_h1.text == 'whoa there, pardner!':
raise IPCooldownException('Your IP is temporarily blocked. Try again later.')
except NoSuchElementException:
pass

# Enter email and go to next page
_logger.debug('Entering email')
email_input = driver.find_element(By.ID, 'regEmail')
Expand All @@ -60,7 +68,7 @@ def create_account(email: str | None = None, username: str | None = None, passwo
else:
if email_err.text != '':
if 'again' in email_err.text.lower():
raise EMailCooldownException(email_err.text)
raise SessionExpiredException(email_err.text)
raise Exception(email_err.text)

# Wait until page loads
Expand Down Expand Up @@ -117,7 +125,14 @@ def create_account(email: str | None = None, username: str | None = None, passwo

if recaptcha_iframe.is_displayed():
solver = RecaptchaSolver(driver)
solver.click_recaptcha_v2(iframe=recaptcha_iframe)
for _ in range(5):
try:
solver.click_recaptcha_v2(iframe=recaptcha_iframe)
break
except ElementClickInterceptedException:
pass
else:
raise RecaptchaException('Could not solve captcha')

# Submit registration
_logger.debug('Submitting registration')
Expand Down
2 changes: 2 additions & 0 deletions reddit_account_generator/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def check_tor_running(ip: str, port: int) -> bool:

def setup_chrome_driver(proxies: dict[str, str] | None = None, hide_browser: bool = True) -> webdriver.Chrome:
options = webdriver.ChromeOptions()
options.add_argument('--lang=en-US')

if hide_browser:
options.add_argument('--headless')
Expand All @@ -74,6 +75,7 @@ def setup_chrome_driver(proxies: dict[str, str] | None = None, hide_browser: boo

def setup_firefox_driver(proxies: dict[str, str] | None = None, hide_browser: bool = True) -> webdriver.Firefox:
options = webdriver.FirefoxOptions()
options.set_preference('intl.accept_languages', 'en-US')

if hide_browser:
options.add_argument('--headless')
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ selenium-recaptcha-solver >=1.4.0, <=1.9.0
random-username >=1.0.0, <=1.0.2
webdriverdownloader >=1.0.0, <=1.1.0.3
stem >=1.8.0, <=1.8.2
static-ffmpeg >=2.3, <=2.5
tempmail-python==2.3.0
11 changes: 6 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ def get_version(ver_file: str) -> str: # Credits to pyTelegramBotAPI setup.py
license='MIT',
keywords='python reddit account-generator account-maker account-generation r-place rplace',
install_requires=[
'selenium==4.8.3',
'selenium-recaptcha-solver==1.9.0',
'random-username==1.0.2',
'webdriverdownloader==1.1.0.3',
'stem==1.8.2',
'selenium >=4.7.0, <=4.9.1',
'selenium-recaptcha-solver >=1.4.0, <=1.9.0',
'random-username >=1.0.0, <=1.0.2',
'webdriverdownloader >=1.0.0, <=1.1.0.3',
'stem >=1.8.0, <=1.8.2',
'static-ffmpeg >=2.3, <=2.5',
'tempmail-python==2.3.0',
],
classifiers=[
Expand Down

0 comments on commit 61e1e3b

Please sign in to comment.