Skip to content

Commit

Permalink
Finished PR
Browse files Browse the repository at this point in the history
  • Loading branch information
cubicbyte committed Aug 25, 2023
1 parent 957332d commit 12a9bd2
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 249 deletions.
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ A python script on selenium to automatically create Reddit accounts.
- [TODO](#todo)
- [Getting started](#getting-started)
- [Script Installation](#script-installation)
- [Script Usage](#command-line-usage)
- [Script Usage](#script-usage)
- [Package Installation](#package-installation)
- [Package Usage](#package-usage)
- [Package Usage](#package-usage-example)
- [Requirements](#requirements)
- [Contributing](#contributing)
- [License](#license)
Expand All @@ -23,22 +23,25 @@ A python script on selenium to automatically create Reddit accounts.

## Features
- **Automatic captcha bypass**: The script automatically solves captchas during the account creation process.
- **Automatic email verification**: The script automatically verifies the email address used for the account.
- **Proxy Support**: Since reddit allows you to create 1 account per IP every 10 minutes, this is very important.
- **Resilience**: The script is able to handle most errors that may occur during the account creation process.

## Quick info

You still need to activate the accounts via email. But it doesn't take much time.

Firefox should be installed on your system for the script to work.

It is recommended to use proxies, because you can only create 1 account per IP in 10 minutes. See file **proxies.txt** or run `python run_tor.py`

To access the auto-generated email, visit https://1secmail.com

If you are not using your email, you should not show anyone the email address generated by the program. Having the address of this email, anyone can access it.

## TODO:
- [x] Add automatic browser driver download
- [x] Add Tor support for easier proxy management
- [x] Make this a python package
- [ ] Automatic email verification
- [x] Automatic email verification
- [ ] Handle error when sub is not available

# Getting started
Expand Down Expand Up @@ -66,7 +69,7 @@ pip install -r requirements-cli.txt
> **Note** **You need to use Tor (not browser) or proxy, because you can only create 1 account per IP in 10 minutes**
#### Using Tor (recommended)
#### Using Tor (recommended for beginners)
Run this command and follow the instructions:
```shell
python run_tor.py
Expand All @@ -75,9 +78,11 @@ python run_tor.py
#### Using proxies
Add your proxies to the proxies.txt file

### Configuration
### Configuring

Open the `config.py` file and put your email to be used on your accounts. Other settings are optional.
Configuring is not needed. But if you want, you can change the settings in the [config.py](config.py) file.

### Starting

1. Run the script:

Expand Down Expand Up @@ -142,7 +147,7 @@ protect_account(username, password)
```

Using proxy:

```python
from reddit_account_generator import create_account, protect_account, install_driver
from reddit_account_generator.proxies import TorProxy
Expand Down
8 changes: 1 addition & 7 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

# You can set here your email if you want, but in that case you need to manually verify account
EMAIL = ''

PROXIES_FILE = 'proxies.txt'
Expand All @@ -12,8 +13,6 @@
# You can set to False if you have Firefox installed
BUILTIN_DRIVER = False
LOG_LEVEL = 'DEBUG' # DEBUG, INFO, WARNING, ERROR, CRITICAL
CREATE_SCRIPT = False
VERIFY_EMAIL = False

# Tor proxy config
TOR_IP = '127.0.0.1'
Expand All @@ -22,8 +21,3 @@
TOR_CONTROL_PORT = 9051
TOR_PASSWORD = 'Passwort'
TOR_DELAY = 5

if VERIFY_EMAIL == False and EMAIL == '':
assert 'Please enter your email in config.py file'
if CREATE_SCRIPT == True and VERIFY_EMAIL == False:
assert 'In order to create a script, you need to have verify email on.'
58 changes: 25 additions & 33 deletions create_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from selenium.common.exceptions import NoSuchWindowException, WebDriverException

from reddit_account_generator import emailVerification, maker, protector, create_account, protect_account, install_driver, scriptCreator, make_script, gen, verify
from reddit_account_generator import maker, protector, verifier, create_account, protect_account, verify_email, install_driver
from reddit_account_generator.proxies import DefaultProxy, TorProxy, EmptyProxy
from reddit_account_generator.utils import *
from reddit_account_generator.exceptions import *
Expand All @@ -26,32 +26,29 @@
logging.warning('Coloredlogs is not installed. Install it with "pip install coloredlogs" to get cool logs!')

# Set config variables
# TODO: Make this better
maker.PAGE_LOAD_TIMEOUT_S = PAGE_LOAD_TIMEOUT_S
maker.DRIVER_TIMEOUT_S = DRIVER_TIMEOUT_S
maker.MICRO_DELAY_S = MICRO_DELAY_S
protector.PAGE_LOAD_TIMEOUT_S = PAGE_LOAD_TIMEOUT_S
protector.DRIVER_TIMEOUT_S = DRIVER_TIMEOUT_S
protector.MICRO_DELAY_S = MICRO_DELAY_S
scriptCreator.PAGE_LOAD_TIMEOUT_S = PAGE_LOAD_TIMEOUT_S
scriptCreator.DRIVER_TIMEOUT_S = DRIVER_TIMEOUT_S
scriptCreator.MICRO_DELAY_S = MICRO_DELAY_S
verifier.PAGE_LOAD_TIMEOUT_S = PAGE_LOAD_TIMEOUT_S
verifier.DRIVER_TIMEOUT_S = DRIVER_TIMEOUT_S
verifier.MICRO_DELAY_S = MICRO_DELAY_S

if BUILTIN_DRIVER:
# Install firefox driver binary
_logger.info('Installing firefox driver...')
install_driver()

if VERIFY_EMAIL == False and CREATE_SCRIPT == True:
raise 'You need to have email verification on if you are creating a script.'

def save_account(email: str, username: str, password: str):
"""Save account credentials to a file."""
_logger.debug('Saving account credentials')
with open(ACCOUNTS_FILE, 'a', encoding='utf-8') as f:
if not CREATE_SCRIPT:
f.write(f'{email};{username};{password}\n')
else:
f.write(f'{email};{username};{password}')
f.write(f'{email};{username};{password}\n')


# Check for tor and proxies
_logger.info('Checking if tor is running...')
Expand Down Expand Up @@ -90,11 +87,11 @@ def save_account(email: str, username: str, password: str):

while True:
try:
if VERIFY_EMAIL == True:
Email = gen()
else:
Email = EMAIL
username, password = create_account(Email, proxies=proxy_, hide_browser=HIDE_BROWSER)
email, username, password = create_account(
email=EMAIL or None,
proxies=proxy_,
hide_browser=HIDE_BROWSER
)
break

except UsernameTakenException:
Expand Down Expand Up @@ -126,14 +123,14 @@ def save_account(email: str, username: str, password: str):
logging.error('An error occurred during account creation. Trying again %s more times...', retries)
username, password = None, None

save_account(Email, username, password)
save_account(email, username, password)
_logger.info('Account created! Protecting account...')

# Try to protect account
for i in range(MAX_RETRIES):
try:
protect_account(username, password, hide_browser=HIDE_BROWSER)
_logger.info('Account protected!\n')
_logger.info('Account protected!')
break

except IncorrectUsernameOrPasswordException:
Expand All @@ -145,21 +142,16 @@ def save_account(email: str, username: str, password: str):
else:
_logger.error('Account protection failed. Skipping...')

if VERIFY_EMAIL:
try:
verify(Email, hide_browser=HIDE_BROWSER)
except Exception as e:
raise e

if CREATE_SCRIPT:
try:
_logger.info('Creating script...')
clientID, clientSecret = make_script(username, password, proxy_, hide_browser=HIDE_BROWSER)
_logger.info('Script created!')
open(ACCOUNTS_FILE, 'a', encoding='utf-8').write(f';{clientID};{clientSecret}\n')
except WebDriverException as e:
_logger.error(e)
_logger.error('An error occurred. Breaking.')
open(ACCOUNTS_FILE, 'a', encoding='utf-8').write(f'\n')
if not EMAIL:
for i in range(MAX_RETRIES):
try:
verify_email(email)
_logger.info('Email verified!\n')
break
except WebDriverException as e:
_logger.error(e)
_logger.error('An error occurred during email verification. Trying again... [%s/%s]', i+1, MAX_RETRIES)
else:
_logger.error('Email verification failed. Skipping...')

_logger.info('Done!')
3 changes: 1 addition & 2 deletions reddit_account_generator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .maker import create_account
from .protector import protect_account
from .scriptCreator import make_script
from .emailVerification import gen, verify
from .verifier import verify_email

def install_driver():
"""Install firefox driver binary."""
Expand Down
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.0.0'
__version__ = '1.3.0'
69 changes: 0 additions & 69 deletions reddit_account_generator/emailVerification.py

This file was deleted.

3 changes: 3 additions & 0 deletions reddit_account_generator/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ class EMailCooldownException(Exception):
class IncorrectUsernameOrPasswordException(Exception):
pass

class EmailVerificationException(Exception):
pass

NetworkException = (RecaptchaException, IPCooldownException, TimeoutException)
16 changes: 9 additions & 7 deletions reddit_account_generator/maker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import time
import logging

from tempmail import EMail
from selenium.common.exceptions import TimeoutException, WebDriverException, NoSuchElementException
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
Expand All @@ -17,8 +18,8 @@
_logger = logging.getLogger(__name__)


def create_account(email: str, username: str | None = None, password: str | None = None,
proxies: dict[str, str] | None = None, hide_browser: bool = True) -> tuple[str, str]:
def create_account(email: str | None = None, username: str | None = None, password: str | None = None,
proxies: dict[str, str] | None = None, hide_browser: bool = True) -> tuple[str, str, str]:
"""Create a Reddit account."""

_logger.info('Creating reddit account')
Expand All @@ -27,6 +28,9 @@ def create_account(email: str, username: str | None = None, password: str | None
if PAGE_LOAD_TIMEOUT_S is not None:
driver.set_page_load_timeout(PAGE_LOAD_TIMEOUT_S)

if email is None:
email = EMail().address

if password is None:
password = generate_password()

Expand Down Expand Up @@ -105,7 +109,7 @@ def create_account(email: str, username: str | None = None, password: str | None
if 'character' in password_err.text.lower():
raise PasswordLengthException(password_err.text)
raise Exception(password_err.text)

# Solve captcha
_logger.debug('Solving captcha')
WebDriverWait(driver, DRIVER_TIMEOUT_S).until(EC.element_to_be_clickable((By.XPATH, '//iframe[@title="reCAPTCHA"]')))
Expand Down Expand Up @@ -135,9 +139,7 @@ def create_account(email: str, username: str | None = None, password: str | None

# Account created!

except Exception as e: # quit driver if error occurs
finally: # quit driver if error occurs
driver.quit()
raise e

driver.quit()
return username, password
return email, username, password
5 changes: 1 addition & 4 deletions reddit_account_generator/protector.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,5 @@ def protect_account(username: str, password: str,

# Done!

except Exception as e: # quit driver if error occurs
finally: # quit driver if error occurs
driver.quit()
raise e

driver.quit()
Loading

0 comments on commit 12a9bd2

Please sign in to comment.