-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
58 lines (46 loc) · 1.79 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import requests
REGISTER_ENDPOINT = "https://api.princeofcrypto.com/v1/user/register?username={}"
def require_confirm_loop(message: str):
while True:
answer = input(f"{message} (Y/N): ").lower()
if answer in ("y", "yes"):
return True
if answer in ("n", "no"):
return False
def require_answer_loop(message: str, default: str):
while True:
answer = input(f"{message}: [{default}] ")
if answer == "":
return default
return answer
def main():
while True:
username = require_answer_loop("Enter your username", "Sun Tzu")
if require_confirm_loop(f'Is "{username}" your username?'):
break
print(f"\nHello, {username}!")
print("I will register you into OVERKILL platform.")
print("Please wait for a moment...\n")
try:
res = requests.post(
REGISTER_ENDPOINT.format(username),
headers={"Content-Type": "application/json"},
)
res.raise_for_status() # Check the response status code and raise an exception for non-200 status codes
except requests.exceptions.RequestException as e:
err_details = e.response.json()
print(f'{err_details.get("result", "Unknown error occurred!")}')
return
user_data = res.json().get("result", "Unknown error occurred!")
success_message = f"""You have been successfully registered!
Your website credentials are:
username: {user_data.get("user_id")}
password: {user_data.get("password")}
Your API key and secret are (required for Headers):
x-api-key: {user_data.get("api_key")}
x-api-secret: {user_data.get("api_secret")}
Please keep your password in a safe place! Password & X_API_SECRET are not recoverable.
"""
print(success_message)
if __name__ == "__main__":
main()