added a way to get the messages recieved

master
kirbylife 2019-10-03 12:40:20 -05:00
parent aa4aafc6c6
commit 76a487b98b
1 changed files with 23 additions and 5 deletions

View File

@ -18,10 +18,13 @@ _HEADERS = {
class TenMinutesEmail: class TenMinutesEmail:
_endpoint = "https://10minutemail.com/10MinuteMail/resources/session/{}".format _endpoint = "https://10minutemail.com/10MinuteMail/resources/session/{}".format
_msg_endpoint = "https://10minutemail.com/10MinuteMail/resources/messages/messagesAfter/{}".format
total_messages = 0
def __init__(self): def __init__(self):
self.created_at = datetime.now() self.created_at = datetime.now()
self.updated_at = datetime.now() self.updated_at = datetime.now()
self.messages = []
r = get("https://10minutemail.com/10MinuteMail/index.html", r = get("https://10minutemail.com/10MinuteMail/index.html",
headers=_HEADERS) headers=_HEADERS)
@ -49,17 +52,32 @@ class TenMinutesEmail:
return (datetime.now() - self.updated_at) < timedelta(minutes=10) return (datetime.now() - self.updated_at) < timedelta(minutes=10)
def reset_time(self): def reset_time(self):
assert (self.is_alive()) assert self.is_alive()
self.updated_at = datetime.now() self.updated_at = datetime.now()
get(self._endpoint("reset"), cookies=self.cookies, headers=_HEADERS) get(self._endpoint("reset"), cookies=self.cookies, headers=_HEADERS)
def seconds_left(self, check_server=False): def seconds_left(self, check_server=False):
assert (self.is_alive())
if check_server: if check_server:
r = get(self._endpoint("secondsLeft"), r = get(self._endpoint("secondsLeft"),
cookies=self.cookies, cookies=self.cookies,
headers=_HEADERS) headers=_HEADERS)
return int(r.text) return int(r.text) % 600
else: else:
if self.is_alive():
return int(600 - return int(600 -
(datetime.now() - self.updated_at).total_seconds()) (datetime.now() - self.updated_at).total_seconds())
else:
return 0
def get_messages(self):
while True:
message = get(self._msg_endpoint(self.total_messages),
cookies=self.cookies,
headers=_HEADERS)
message = message.json()
if message:
self.messages.append(message[0])
self.total_messages += 1
else:
break
return self.messages