299 lines
9.1 KiB
Python
299 lines
9.1 KiB
Python
import time
|
|
from datetime import datetime
|
|
|
|
from faker import Faker
|
|
from selenium import webdriver
|
|
from selenium.webdriver import ActionChains
|
|
from selenium.webdriver.common.by import By
|
|
from selenium.webdriver.common.keys import Keys
|
|
from selenium.webdriver.support.ui import Select
|
|
from selenium.webdriver.chrome.service import Service
|
|
from smspool import smspool
|
|
from webdriver_manager.chrome import ChromeDriverManager
|
|
|
|
from urllib.parse import urlparse, urlunparse
|
|
|
|
import addy_api
|
|
import smspool_api
|
|
|
|
|
|
def test_url_ignore_params(driver: webdriver, expected_url: str) -> None:
|
|
"""
|
|
Assert that the current URL matches the expected URL, ignoring query parameters and anchors.
|
|
|
|
:param driver: The Selenium webdriver instance
|
|
:type driver: webdriver
|
|
:param expected_url: The URL we expect to be in
|
|
:type expected_url: str
|
|
:raises AssertionError: If the current URL (ignoring query parameters and anchors) does not match the expected URL
|
|
"""
|
|
|
|
actual_url = remove_query_and_anchor(driver.current_url)
|
|
expected_url = remove_query_and_anchor(expected_url)
|
|
|
|
|
|
def remove_query_and_anchor(url: str) -> str:
|
|
"""
|
|
Removes query parameters and anchors from a URL.
|
|
|
|
:param url: The original URL
|
|
:type url: str
|
|
:return: The URL with query parameters and anchors removed
|
|
:rtype: str
|
|
"""
|
|
parsed = urlparse(url)
|
|
return urlunparse(parsed._replace(params='', query='', fragment=''))
|
|
|
|
|
|
def load_keys(file_path):
|
|
keys = {}
|
|
with open(file_path, 'r') as file:
|
|
for line in file:
|
|
# Split the line into key and value
|
|
parts = line.strip().split('=', 1)
|
|
if len(parts) == 2:
|
|
# Strip spaces from key and value, then add to the dictionary
|
|
key, value = parts[0].strip(), parts[1].strip()
|
|
keys[key] = value
|
|
return keys
|
|
|
|
|
|
def append_api_key_to_file(filename, name, api_key):
|
|
"""
|
|
Appends an API key to a file with the current date in a specific format.
|
|
|
|
:param filename: The name of the file to append the API key to.
|
|
:param name: The name associated with the API key.
|
|
:param api_key: The API key to append.
|
|
"""
|
|
# Get the current date and format it
|
|
current_date = datetime.now().strftime("%d.%m.%Y")
|
|
|
|
# Format the string to append
|
|
entry = f"\n{name} ({current_date})\n{api_key}\n"
|
|
|
|
# Open the file in append mode and write the entry
|
|
with open(filename, 'a') as file:
|
|
file.write(entry)
|
|
|
|
|
|
def get_key():
|
|
# Usage
|
|
secrets = load_keys('keys.secret')
|
|
# print(keys_data)
|
|
|
|
CHROMIUM_PATH = '/usr/bin/chromium-browser'
|
|
|
|
options = webdriver.ChromeOptions()
|
|
options.binary_location = CHROMIUM_PATH
|
|
# Set up the Chrome WebDriver
|
|
driver = webdriver.Chrome(options=options)
|
|
|
|
# Open the Google homepage
|
|
driver.get("https://console.anthropic.com/login")
|
|
|
|
print('doing signup step')
|
|
onboarding = False
|
|
|
|
# Find the search box using its name attribute value
|
|
email_box = driver.find_element("id", "email")
|
|
|
|
# get new alias
|
|
alias = addy_api.create_alias(api_token=secrets['ANONADDY_API_KEY'], alias_domain='addy.io',
|
|
alias_description='temp alias for anthropic')
|
|
|
|
print(alias)
|
|
mail = alias['data']['email']
|
|
|
|
email_box.send_keys(mail)
|
|
email_box.send_keys(Keys.ENTER)
|
|
|
|
while not onboarding:
|
|
|
|
while True:
|
|
try:
|
|
login_code = input("Check your inbox for the login code!\nLogin Code > ")
|
|
if len(login_code.strip()) != 6:
|
|
print("Make sure to enter the six digit number!")
|
|
continue
|
|
int(login_code)
|
|
break
|
|
except ValueError as e:
|
|
print("An error occurred. Make sure to enter a six digit integer.")
|
|
|
|
code_box = driver.find_element("id", "code")
|
|
code_box.clear()
|
|
code_box.send_keys(str(login_code))
|
|
code_box.send_keys(Keys.RETURN)
|
|
|
|
on_onboarding_page = lambda: remove_query_and_anchor(driver.current_url).endswith('onboarding')
|
|
|
|
for i in range(10):
|
|
if on_onboarding_page():
|
|
break
|
|
time.sleep(1)
|
|
|
|
if on_onboarding_page():
|
|
onboarding = True
|
|
else:
|
|
print('Seems like you entered the wrong code. Try again please!')
|
|
|
|
# print('deleting mail alias...')
|
|
|
|
print('doing onboarding step...')
|
|
onboarding_done = False
|
|
fake = Faker()
|
|
|
|
while not onboarding_done:
|
|
name = fake.name()
|
|
|
|
time.sleep(2)
|
|
|
|
name_field = driver.find_element('id', 'fullName_1')
|
|
name_field.send_keys(name)
|
|
|
|
eighteen_checkbox = driver.find_element('id', ':r1:')
|
|
eighteen_checkbox.click()
|
|
|
|
time.sleep(2)
|
|
|
|
continue_button = driver.find_element('xpath', "//button[normalize-space()='Continue']")
|
|
continue_button.click()
|
|
|
|
on_create_page = lambda: remove_query_and_anchor(driver.current_url).endswith('create')
|
|
|
|
for i in range(10):
|
|
if on_create_page():
|
|
break
|
|
time.sleep(1)
|
|
|
|
if on_create_page():
|
|
onboarding_done = True
|
|
else:
|
|
print('onboarding partially failed, retrying...')
|
|
|
|
print('doing create step...')
|
|
create_done = False
|
|
|
|
while not create_done:
|
|
company = fake.company()
|
|
|
|
time.sleep(2)
|
|
|
|
org_field = driver.find_element('id', 'organizationName_3')
|
|
org_field.send_keys(company)
|
|
|
|
continue_button = driver.find_element('xpath', "//button[normalize-space()='Create account']")
|
|
continue_button.click()
|
|
|
|
on_create_page = lambda: remove_query_and_anchor(driver.current_url).endswith('create')
|
|
|
|
for i in range(10):
|
|
if not on_create_page():
|
|
break
|
|
time.sleep(1)
|
|
|
|
if not on_create_page():
|
|
create_done = True
|
|
else:
|
|
print('onboarding partially failed, retrying...')
|
|
|
|
print('on dashboard page now')
|
|
print('starting sms verification')
|
|
|
|
sms_done = False
|
|
|
|
while not sms_done:
|
|
time.sleep(2)
|
|
|
|
claim_button = driver.find_element('xpath', "//button[normalize-space()='Claim']")
|
|
claim_button.click()
|
|
time.sleep(1)
|
|
|
|
country_dropdown = driver.find_element(By.CLASS_NAME, 'PhoneInputCountrySelect')
|
|
select = Select(country_dropdown)
|
|
select.select_by_value('GB')
|
|
|
|
phone_num_field = driver.find_element('id', 'free_credits_phone_number')
|
|
|
|
# input('enter > ')
|
|
|
|
# get new phone number for verification
|
|
sms = smspool_api.post_order_sms(bearer_token=secrets['SMSPOOL_API_KEY'], country='GB',
|
|
service='817') # service='1371') # ClaudeAI
|
|
print(sms)
|
|
|
|
number = sms['number']
|
|
|
|
phone_num_field.send_keys(number)
|
|
phone_num_field.send_keys(Keys.ENTER)
|
|
|
|
while True:
|
|
val = smspool_api.check_sms_status(bearer_token=secrets['SMSPOOL_API_KEY'], order_id=sms['order_id'])
|
|
print(val)
|
|
if 'status' not in val.keys():
|
|
print(f'success key not found in val {val}. Why?')
|
|
elif val['status'] == 0 or val['status'] == 1:
|
|
print(f'sms not yet received: {val}')
|
|
elif val['status'] == 3:
|
|
code = val['sms']
|
|
print(f'sms received, code: {code}')
|
|
|
|
# TODO: input SMS
|
|
|
|
number_input = driver.find_element('id', '4')
|
|
number_input.send_keys(code)
|
|
number_input.send_keys(Keys.ENTER)
|
|
time.sleep(6) # takes long
|
|
|
|
sms_done = True
|
|
break
|
|
else:
|
|
print(f'sms receive error: {val}')
|
|
|
|
time.sleep(3)
|
|
|
|
# get API key
|
|
time.sleep(2)
|
|
|
|
# # find the profile picture thingy div
|
|
# css_selector = ".font-bold.rounded-full.flex.items-center.justify-center.h-8.w-8.text-\\[14px\\].bg-text-200.text-bg-100"
|
|
#
|
|
# # Find the element using the CSS selector
|
|
# profile_pic = driver.find_element("css selector", css_selector)
|
|
# profile_pic.click()
|
|
# time.sleep(1)
|
|
#
|
|
# api_keys_button = driver.find_element('xpath', '//*[@id="radix-:r8:"]/a[4]/div')
|
|
# api_keys_button.click()
|
|
|
|
driver.get('https://console.anthropic.com/settings/keys')
|
|
time.sleep(3)
|
|
|
|
create_key_button = driver.find_element('xpath', "//button[normalize-space()='Create Key']")
|
|
create_key_button.click()
|
|
time.sleep(1)
|
|
|
|
key_name_field = driver.find_element("css selector",
|
|
"[id^='nameYourKey_']") # starts with, but last number increments
|
|
key_name_field.send_keys('my-secret-key')
|
|
|
|
actions = ActionChains(driver)
|
|
|
|
actions.send_keys(Keys.TAB).perform()
|
|
actions.send_keys(Keys.ENTER).perform()
|
|
|
|
time.sleep(1)
|
|
|
|
key_text = driver.find_element("xpath", "//p[starts-with(text(), 'sk-ant-')]").text
|
|
print('key:', key_text)
|
|
addy_api.delete_alias(api_token=secrets['ANONADDY_API_KEY'], alias_id=alias['data']['id'])
|
|
return key_text, name
|
|
|
|
# delete alias
|
|
|
|
|
|
if __name__ == '__main__':
|
|
key, name = get_key()
|
|
append_api_key_to_file('apikeys.txt', name, key)
|