Skip to content

Instantly share code, notes, and snippets.

@zeroruka
Last active August 29, 2023 05:26
Show Gist options
  • Save zeroruka/31204a6b644cdee6f98af00e1b19335c to your computer and use it in GitHub Desktop.
Save zeroruka/31204a6b644cdee6f98af00e1b19335c to your computer and use it in GitHub Desktop.
Reddit Account Scripts
# Lines to modify: 19, 207, 212, 223
import os
import time
import names
import string
import random
import requests
from termcolor import colored
from selenium import webdriver
from twocaptcha import TwoCaptcha
from selenium.webdriver.common.by import By
from random_user_agent.user_agent import UserAgent
from selenium.webdriver.firefox.options import Options
from random_user_agent.params import SoftwareName, OperatingSystem
sitekey = "6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC"
api = "" # 2captcha apikey
uri = "https://old.reddit.com/register"
# make account
def main():
# repeat the code block 100 times
for i in range(100): # Change this number to modify amount of accounts created. Number of accounts created will not be exact.
info(f"Creating account {i + 1}")
driver, useragent = make_driver()
username, passwd = generateuser(useragent)
driver.get("https://old.reddit.com/register")
time.sleep(random.randint(1, 3))
info("Entering username...")
driver.find_element(By.ID, "user_reg").click()
driver.find_element(By.ID, "user_reg").send_keys(username)
success(f"Using username {username}")
time.sleep(random.randint(1, 3))
info("Entering password...")
driver.find_element(By.ID, "passwd_reg").click()
driver.find_element(By.ID, "passwd_reg").send_keys(passwd)
success(f"Using password {passwd}")
time.sleep(random.randint(1, 5))
info("Entering 2nd password...")
driver.find_element(By.ID, "passwd2_reg").click()
driver.find_element(By.ID, "passwd2_reg").send_keys(passwd)
time.sleep(random.randint(2, 5))
# print("Getting email")
# driver.execute_script("window.open('about:blank', 'tab2');")
# driver.switch_to.window("tab2")
# driver.get("https://getnada.com")
# time.sleep(2)
# email = driver.find_element(
# By.XPATH, '//*[@id="__layout"]/div/div/div[2]/nav/div/div/ul[2]/li/span'
# ).text
# print(f"Got email: {email}")
# print("Entering email")
# driver.switch_to.window(driver.window_handles[0])
# time.sleep(random.randint(1, 5))
# driver.find_element(By.ID, "email_reg").send_keys(email)
# time.sleep(2)
# Test ratelimit
driver.find_element(By.CLASS_NAME, "c-pull-right").click()
time.sleep(3)
info("Testing ratelimit..")
if test_for_ratelimit(driver):
success("No ratelimit")
else:
error("Ratelimit found, restarting Tor...")
restart_tor(driver)
continue
# Test captcha
time.sleep(2)
info("Testing captcha...")
if test_for_captcha(driver):
success("Captcha found")
captchaInput = driver.find_element(By.ID, "g-recaptcha-response")
driver.execute_script(
"arguments[0].setAttribute('style','visibility:visible;');", captchaInput,)
else:
error("No captcha found, restarting Tor...")
restart_tor(driver)
continue
# Solve captcha
info("Solving captcha")
try:
resp = captcha(uri, sitekey, api)
success("Solved captcha")
captchaInput.send_keys(resp["code"])
except:
error("Failed to solve captcha, restarting Tor...")
restart_tor(driver)
continue
# Register
time.sleep(2)
driver.find_element(By.CLASS_NAME, "c-pull-right").click()
# print("Waiting for email")
# time.sleep(10)
if create_account(driver):
success("Account created")
with open("accounts.txt", "a+") as f:
f.write(f"{username} {passwd}\n")
info("Restarting Tor...")
restart_tor(driver)
else:
error("Failed to create account, restarting Tor...")
restart_tor(driver)
continue
# verify_email(driver)
# time.sleep(15)
# print("Account created, waiting 7 minutes")
# rand = random.randint(480, 500)
# for j in range(rand):
# print(f"Time left: {rand - j} seconds", end="\r")
# time.sleep(1)
def error(message):
print(colored("[ERROR]", "red"), message)
def info(message):
print(colored("[INFO]", "grey"), message)
def success(message):
print(colored("[SUCCESS]", "green"), message)
def create_account(driver):
k = 0
while True:
if k == 5:
return False
try:
driver.find_element(
By.XPATH, '//*[contains(text(), "Create your own subreddit")]')
return True
except:
time.sleep(5)
k = + 1
# generates username and password
def generateuser(useragent):
uri = "https://old.reddit.com/api/v1/generate_username.json?"
hdr = {
"accept": "application/json, text/javascript, */*; q=0.01",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"referer": "https://old.reddit.com/signup",
"user-agent": useragent,
}
res = requests.get(uri, headers=hdr)
if res.status_code == 429:
username = names.get_first_name()
username += "".join(
str(random.randint(0, 9)) for i in range(random.randint(5, 15))
)
else:
b = res.json()
username = random.choice(b["usernames"])
passwd = "".join(
random.choice(string.ascii_letters + string.digits)
for i in range(random.randint(10, 15))
)
return username, passwd
# solves captcha using 2cpatcha
def captcha(uri, sitekey, api):
solver = TwoCaptcha(api)
result = solver.recaptcha(sitekey=sitekey, url=uri)
return result
# initializes the webdriver
def make_driver():
software_names = [SoftwareName.FIREFOX.value]
operating_systems = [OperatingSystem.WINDOWS.value,
OperatingSystem.LINUX.value]
user_agent_rotator = UserAgent(
software_names=software_names, operating_systems=operating_systems, limit=100
)
useragent = user_agent_rotator.get_random_user_agent()
profile_path = r"/home/USER/.mozilla/firefox/SOMENUMBERS.default-release" # Change to your profile path
options = Options()
options.set_preference('profile', profile_path)
options.set_preference("network.proxy.type", 1)
options.set_preference("network.proxy.socks", '127.0.0.1')
options.set_preference("network.proxy.socks_port", 9050)
options.set_preference("network.proxy.socks_remote_dns", True)
driver = webdriver.Firefox(options=options)
return driver, useragent
def restart_tor(driver):
driver.close()
driver.quit()
os.system('echo YOUR_PASSWORD | sudo -S systemctl restart tor') # Change this based on your os
def test_for_captcha(driver):
k = 0
while True:
if k == 5:
return False
try:
time.sleep(3)
driver.find_element(By.ID, "g-recaptcha-response")
return True
except:
k += 1
time.sleep(10)
def test_for_ratelimit(driver):
k = 0
while True:
if k == 3:
return False
try:
driver.find_element(By.XPATH, '//*[contains(text(), "tricky")]')
return True
except:
k += 1
time.sleep(1)
# verify the email address
# def verify_email(driver):
# driver.switch_to.window("tab2")
# time.sleep(10)
# k = 0
# while True:
# if k == 5:
# print("Cannot verify email")
# driver.close()
# sys.exit()
# try:
# driver.find_element(
# By.XPATH, "//a[contains(text(), 'Verify your Reddit email address')]"
# ).click()
# print("got email")
# break
# except:
# time.sleep(10)
# k = k + 1
# time.sleep(17)
# print("Getting links")
# iframe = driver.find_element(By.ID, "the_message_iframe")
# driver.switch_to.frame(iframe)
# time.sleep(3)
# driver.find_element(
# By.XPATH,
# "/html/body/center/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[3]/td/table/tbody/tr/td/a",
# ).click()
if __name__ == "__main__":
main()
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
loginFile = 'accounts.txt'
# update with comment link or post link to upvote (must be old.reddit site)
postLink = ''
commentPermaLink = ''
def upvote_post(browser, username, password, postLink):
# insert username
browser.find_element(By.NAME, "user").click()
browser.find_element(By.NAME, "user").send_keys(username)
# insert password
browser.find_element(By.NAME, "passwd").click()
browser.find_element(By.NAME, "passwd").send_keys(password)
# login
print(f"Logged in to {username}")
browser.find_element(By.CSS_SELECTOR, '.btn').click()
time.sleep(2)
# get link page
browser.get(postLink)
browser.find_element(
By.CSS_SELECTOR, 'div.midcol:nth-child(3) > div:nth-child(1)').click()
browser.find_element(By.CSS_SELECTOR, '.logout > a:nth-child(4)').click()
time.sleep(2)
browser.get('http://www.old.reddit.com')
def upvote_comment(browser, username, password, commentLink):
# insert username
browser.find_element(By.NAME, "user").click()
browser.find_element(By.NAME, "user").send_keys(username)
# insert password
browser.find_element(By.NAME, "passwd").click()
browser.find_element(By.NAME, "passwd").send_keys(password)
# login
browser.find_element(By.CSS_SELECTOR, '.btn').click()
time.sleep(2)
# get link page
browser.get(commentLink)
browser.find_element(By.CSS_SELECTOR,
'div.midcol:nth-child(2) > div:nth-child(1)').click()
# logout
browser.find_element(By.CSS_SELECTOR, '.logout > a:nth-child(4)').click()
time.sleep(2)
browser.get('http://www.old.reddit.com')
def main():
browser = webdriver.Firefox()
browser.get('http://old.reddit.com')
# comment out post or comment depending on what you'd like to upvote
creds = [cred.strip() for cred in open(loginFile).readlines()]
for cred in creds:
username, password = cred.split(' ')
# upvote_comment(browser, username, password, commentPermaLink)
upvote_post(browser, username, password, postLink)
# restart_tor(browser)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment