-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_api.py
More file actions
45 lines (38 loc) · 1.52 KB
/
Copy pathemail_api.py
File metadata and controls
45 lines (38 loc) · 1.52 KB
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
import time
import secrets
import requests
class KopechkaAPI:
def __init__(self, api_key):
self.base_url = 'https://api.kopechka.com/api/v1'
self.headers = {
'X-API-Key': api_key,
'Content-Type': 'application/json'
}
def get_balance(self):
response = requests.get(f'{self.base_url}/balance', headers=self.headers)
return response.json()
def create_order(self, domain, site):
while True:
try:
data = {'domain': domain, 'site': site}
response = requests.post(f'{self.base_url}/orders', json=data, headers=self.headers).json()
data = response['data']
return {"email": data["email"], "password": secrets.token_hex(8) + '1D', "token": data['orderId']}
except:
print("[!] Mail bekleniyor..")
time.sleep(2)
def get_messages(self, order_id):
print(f"[{order_id}] Wait code...")
time.sleep(2)
for _ in range(10):
try:
response = requests.get(f'{self.base_url}/orders/{order_id}/messages', headers=self.headers).json()
return response['messages'][0]['body'].split('confirmation_token%3D')[1].split('"')[0]
except:
pass
time.sleep(5)
else:
return None
def cancel_order(self, order_id):
response = requests.delete(f'{self.base_url}/orders/{order_id}', headers=self.headers)
return response.json()