Untitled

mail@pastecode.io avatar
unknown
python
a year ago
22 kB
10
Indexable
Never
def register(proxy):
    url = f"https://reddit.com/register"
    release_ip(proxy=proxy)

    proxy = proxy['proxy']
    password = passgen.passgen()


    # try:
    #     data = kopeechka_body.mailbox_get_email(site="reddit.com",
    #                                                  mail_type="hotmail.com",
    #                                                  sender="noreply@reddit.com")
    #     email_address = data.mail
    #     task_id = data.id
    #     print(email_address)
    # except Exception as e:
    #     print(e)
    #     return False

    random_string = ''.join(random.choices(string.ascii_letters, k=random.randint(4, 6)))
    random_string += ''.join(random.choices(string.digits, k=random.randint(3, 5)))
    email_address = f"{random_string}@gmail.com"

    # while True:
    #     username = f"{random.choice(adjectives).capitalize()}_{random.choice(nouns).capitalize()}_{int(random.randint(20, 700))}"
    #     if 7 < len(username) < 20:
    #         break

    # print(username)
    # print(f"Email address is: {email_address}")

    headers = {
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
    }

    release_ip(proxy={"proxy": proxy})

    session = httpx.Client()
    session.headers = headers
    # session.verify = False

    session.proxies = {
        "http": f"http://{proxy}",
        "https": f"https://{proxy}"
    }

    try:
        for _ in range(3):
            try:
                response = session.get(url, follow_redirects=True)
                break
            except Exception as e:
                pass

        print(f"Getting registration page: {response.status_code}")

        soup = bs(response.content, "lxml")
        token = soup.findAll('input')[1]['value']
        # print(f"My first token is: {token}")

        # GETTING USERNAMES
        for _ in range(3):
            try:
                response = session.get('https://www.reddit.com/api/v1/generate_username.json', follow_redirects=True)
                break
            except Exception as e:
                pass

        username = random.choice(response.json()['usernames'])
        print(f"Username is: {username}")

        # captcha
        captcha_key = ""
        site_key = "6LeTnxkTAAAAAN9QEuDZRpn90WwKk_R1TRW_g-JC"
        site_url = "https://reddit.com/register"
        send_captcha = "https://ocr.captchaai.com/in.php"
        get_captcha = "https://ocr.captchaai.com/res.php"

        params = {
            "key": captcha_key,
            "method": "userrecaptcha",
            "googlekey": site_key,
            "pageurl": site_url
        }
        g_response = None
        try:

            response = requests.get(send_captcha, params=params)

            task_id = response.content.decode().split("|")[1]

            # print(task_id)

            params = {
                "key": captcha_key,
                "action": "get",
                "id": task_id,
            }

            captcha_fails = 0
            while True:
                if captcha_fails >= 8:
                    print(f"We could not solve captcha.")
                    break
                try:
                    res = requests.get(get_captcha, params=params, timeout=22)
                    g_response = res.content.decode().split("|")[1]
                    # print(g_response)
                    break
                except IndexError:
                    # print(f"Captcha still processing.")
                    captcha_fails += 1
                    time.sleep(10)
                    continue
        except Exception as e:
            # print(e)
            session.close()
            return False

        if token is None:
            session.close()
            print(f"Failed to get token.")
            return False

        if g_response:

            session.headers.update({
                'authority': 'www.reddit.com',
                'accept': '*/*',
                'accept-language': 'en-US,en;q=0.9',
                'content-type': 'application/x-www-form-urlencoded',
                'origin': 'https://www.reddit.com',
                'referer': 'https://www.reddit.com/register/',
                'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                'sec-ch-ua-mobile': '?0',
                'sec-ch-ua-platform': '"Windows"',
                'sec-fetch-dest': 'empty',
                'sec-fetch-mode': 'cors',
                'sec-fetch-site': 'same-origin',
                'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
            })

            data = {
                'csrf_token': f'{token}',
                'g-recaptcha-response': f'{g_response}',
                'password': f'{password}',
                'dest': 'https://www.reddit.com',
                'email_permission': 'false',
                'lang': 'en-US',
                'username': f'{username}',
                'email': f'{email_address}',
            }

            # registering
            for _ in range(4):
                try:
                    response = session.post('https://www.reddit.com/register', data=data, follow_redirects=True)
                    break
                except Exception as e:
                    pass

            # session.close()

            # print(f"Registering response: {response.status_code}")

            if response.status_code != 200:
                print(response.content)

            if response.status_code == 200:
                today = datetime.strftime(datetime.today(), "%Y-%m-%d")
                created_accounts.insert_one({
                    'username': username,
                    'password': password,
                    'email': email_address,
                    'age': today,
                    'verified': False,
                    'requests': True
                })

                session, loid, bearer = get_loid_and_bearer_from_url(url="https://reddit.com", session=session)

                session.headers = {}

                session.headers = {
                    'authority': 'gql.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'content-type': 'application/json',
                    'authorization': f'Bearer {bearer}',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-ch-ua-platform': '"Windows"',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
                    'x-reddit-compression': '1',
                    'x-reddit-loid': f'{loid}',
                }

                json_data = {
                    'id': '670e8e8d3018',
                    'variables': {
                        'input': {
                            'customGender': None,
                            'genderEnum': 'FEMALE',
                        },
                    },
                }

                for _ in range(4):
                    try:
                        response = session.post('https://gql.reddit.com/', json=json_data, follow_redirects=True)
                        break
                    except Exception as e:
                        pass

                # print(f"Sending gender response: {response.status_code}")

                if response.status_code != 200:
                    print(response.content)
                    session.close()
                    quit(0)

                # GETTING THE INTERESTS
                json_data = {
                    'id': '7637265b3b63',
                    'variables': {
                        'first': 500,
                        'maxChildren': 500,
                        'maxDepth': 2,
                        'schemeName': 'topic_chaining_icons',
                        'onboardingFlow': 'ONBOARDING',
                    },
                }

                for _ in range(4):
                    try:
                        response = session.post('https://gql.reddit.com/', json=json_data, follow_redirects=True)
                        break
                    except Exception as e:
                        pass

                # print(f"Getting interests response: {response.status_code}")

                session.headers = {}

                session.headers = {
                    'authority': 'gql.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'authorization': f'Bearer {bearer}',
                    'content-type': 'application/json',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-ch-ua-platform': '"Windows"',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
                    'x-reddit-compression': '1',
                    'x-reddit-loid': f'{loid}',
                }

                # TODO: parse the interests and pick randomly.
                response_str = response.content.decode('utf-8')
                json_data = json.loads(response_str)

                edges = json_data['data']['interestTopics']['edges']
                random.shuffle(edges)
                interest_blocks = edges[:5]
                random_interests = []
                for one in interest_blocks:
                    interest = one['node']['id']
                    random_interests.append(interest)

                # print(f"My interests: {random_interests}")

                json_data = {
                    'id': 'c79807b42f04',
                    'variables': {
                        'topicIds': random_interests,
                        'schemeName': 'topic_chaining_icons',
                        'maxSubreddits': 10,
                        'onboardingFlow': 'ONBOARDING',
                    },
                }

                for _ in range(4):
                    try:
                        response = session.post('https://gql.reddit.com/', json=json_data, follow_redirects=True)
                        break
                    except Exception as e:
                        pass

                print(f"Sending interests response: {response.status_code}")

                # if response.status_code != 200:
                #     # print(response.content)

                # print(f"interests response: {response.content}")

                # TODO: the content of the response here has the subreddits.
                # TODO: get the subreddits after sending the interests.
                response_str = response.content.decode('utf-8')
                json_data = json.loads(response_str)

                topics = json_data['data']['interestTopicsByIds']['edges']
                random.shuffle(edges)
                random_subs = []
                for one in topics:
                    subreddits = one['node']['topic']['subreddits']['edges']
                    random.shuffle(subreddits)
                    random_sub = subreddits[0]['node']['id']
                    random_subs.append(random_sub)

                my_chosen_subs = ",".join(random_subs)
                # print(my_chosen_subs)

                sleep(random.randint(2, 4))

                session.headers = {}

                session.headers = {
                    'authority': 'oauth.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'authorization': f'Bearer {bearer}',
                    'content-type': 'application/x-www-form-urlencoded',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-ch-ua-platform': '"Windows"',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
                    'x-reddit-loid': f'{loid}'
                }

                params = {
                    'redditWebClient': 'desktop2x',
                    'app': 'desktop2x-client-production',
                    'raw_json': '1',
                    'gilding_detail': '1',
                }

                data = {
                    'action': 'sub',
                    'sr': f'{my_chosen_subs}',
                    'api_type': 'json',
                }

                for _ in range(4):
                    try:
                        response = session.post('https://oauth.reddit.com/api/subscribe',
                                                params=params,
                                                data=data, follow_redirects=True)
                        break
                    except Exception as e:
                        pass

                # print(f"Sending subreddits response: {response.status_code}")

                print(f"Username: {username} - Password: {password}")

                sleep(random.randint(4, 8))

                # getting the csrf token we need
                session.headers = {}

                # GETTING A RANDOM AVATAR
                session.headers = {
                    'authority': 'snoovatar.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'authorization': f'Bearer {bearer}',
                    'content-type': 'application/x-www-form-urlencoded',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-ch-ua-platform': '"Windows"',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
                    'x-reddit-loid': f'{loid}'
                }

                for _ in range(4):
                    try:
                        response = session.get('https://snoovatar.reddit.com/api/account',
                                               headers=headers,
                                               follow_redirects=True)
                    except Exception as e:
                        print(e)

                # print(f"Getting second token response: {response.status_code}")
                # print(response.content)
                content = response.json()
                csrf_token = content['csrf_token']
                # print(csrf_token)

                session.headers = {}

                # GETTING A RANDOM AVATAR
                session.headers = {
                    'authority': 'snoovatar.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'authorization': f'Bearer {bearer}',
                    'content-type': 'application/x-www-form-urlencoded',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-ch-ua-platform': '"Windows"',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
                    'x-reddit-loid': f'{loid}'
                }

                response = session.get('https://snoovatar.reddit.com/api/snoovatars/random:byId', follow_redirects=True)

                # print(f"Getting a random avatar response: {response.status_code}")
                # print(f"avatar response: {response.content}")

                sleep(random.randint(4, 7))

                content = response.json()
                items = content['accessory_ids']
                # print(f"Avatar Items: {items}")

                session.headers = {}
                session.headers = {
                    'authority': 'snoovatar.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'access-control-request-headers': 'authorization,content-type,x-csrf-token,x-reddit-loid,x-reddit-session',
                    'access-control-request-method': 'POST',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36',
                }

                params = {
                    'skip_telemetry': 'true',
                }

                response = session.options('https://snoovatar.reddit.com/api/snoovatar',
                                           params=params,
                                           follow_redirects=True)

                # print(f"Sending avatar options response: {response.status_code}")

                # session_tracker = ""
                #
                # for one in session.cookies.items():
                #     name = one[0].lower()
                #     value = one[1]
                #
                #     if name == "session_tracker":
                #         session_tracker = value
                #
                # print(f"My session tracker is: {session_tracker}")

                session.headers = {}
                session.headers = {
                    'authority': 'snoovatar.reddit.com',
                    'accept': '*/*',
                    'accept-language': 'en-US,en;q=0.9',
                    'authorization': f'Bearer {bearer}',
                    'content-type': 'application/json',
                    'origin': 'https://www.reddit.com',
                    'referer': 'https://www.reddit.com/',
                    'sec-ch-ua': '"Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
                    'sec-ch-ua-mobile': '?0',
                    'sec-ch-ua-platform': '"Windows"',
                    'sec-fetch-dest': 'empty',
                    'sec-fetch-mode': 'cors',
                    'sec-fetch-site': 'same-site',
                    'user-agent': "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
                    'x-csrf-token': f'{csrf_token}',
                    'x-reddit-loid': f'{loid}'
                }

                params = {
                    'skip_telemetry': 'true',
                }

                json_data = OrderedDict([
                    ('accessory_ids', items),
                    ('styles', {}),
                    ('set_avatar_to_profile', True),
                    ('source', 'web_onboarding')
                ])

                # print(json_data)

                response = session.post('https://snoovatar.reddit.com/api/snoovatar',
                                        params=params,
                                        json=json_data,
                                        follow_redirects=True)

                print(f"Choosing avatar response: {response.status_code}")
                # print(f"{response.content}")

                # verify_with_kopeechka(
                #                 username=username,
                #                 session=session,
                #                 task_id=task_id,
                #                 proxy_address=proxy)

                session.close()

                return True
        else:
            # print(response.content)
            session.close()
            return False

    except Exception as e:
        print(e)
        session.close()