-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSimpleTempMailPlus.py
More file actions
67 lines (53 loc) · 2.2 KB
/
SimpleTempMailPlus.py
File metadata and controls
67 lines (53 loc) · 2.2 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import requests
import random
import string
import json
from time import sleep
class Tempmail():
def __init__(self, name, domain, __last_req=None):
self.name = name
self.domain = domain
self.__last_req = __last_req
def create(self):
'''Creates mailbox'''
self.__last_req = requests.get(
url=f'https://tempmail.plus/api/mails?email={self.name}{self.domain}&limit=20&epin=').json()
def update(self, timeout=3):
'''Updates info in json about mailbox'''
r = requests.get(
url=f'https://tempmail.plus/api/mails?email={self.name}{self.domain}&first_id=0&epin=')
if r.status_code != 200:
raise Exception(
f'Something went wrong while updating.\nStatus code: {r.status_code}')
self.__last_req = r.json()
sleep(timeout)
def is_empty(self):
'''Returns True or False if mailbox contains any messages'''
return self.__last_req.get('count') <= 0
def first_message(self):
'''Returns first message text in mailbox'''
return self.__request_message('last_id')
def last_message(self):
'''Returns last message text in mailbox'''
return self.__request_message('first_id')
def __request_message(self, position):
message_id = self.__last_req.get(position)
r = requests.get(
url=f'https://tempmail.plus/api/mails/{message_id}?email={self.name}{self.domain}&epin='
)
return json.loads(json.dumps(r.json().get('text')))
def get_domains():
'''Returns list of all domains'''
return ['@mailto.plus', '@fexpost.com', '@fexbox.org',
'@fexbox.ru', '@mailbox.in.ua', '@rover.info',
'@inpwa.com', '@intopwa.com', '@tofeat.com',
'@chitthi.in']
def generate_name(length=16):
'''Returns randomly generated name'''
return ''.join(
random.choice(string.ascii_lowercase + string.digits)
for _ in range(length)
)
def get_random_domain():
'''Returns random domain'''
return Tempmail.get_domains()[random.randint(0, 9)]