-
Notifications
You must be signed in to change notification settings - Fork 0
/
TenMinuteMailAPI.py
130 lines (94 loc) · 3.15 KB
/
TenMinuteMailAPI.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import requests as rq
class Mails(object):
"""
Mails is a interface for the https://10minutemail.com website that
supplies single use mails.
...
Attributes
----------
cookies : str
a string with all the cookies
emailAddress : str
supplied email address
Methods
-------
getEmailAddress(self) : str
Prints the animals name and what sound it makes
getEmailCount(self) : int
Counts the number of emails in the inbox
getAllEmails(self) : list
Gets all the emails in the inbox
getSecondsLeft(self) : int
Gets the remaining time in the email
isExpired(self) : bool
Verifies if the session has expired
refreshTime(self) : bool
Refreshes the duration of the email
"""
def __init__(self):
"""Init method establishes a session and stores the email"""
response = rq.get('https://10minutemail.com/session/address')
self.cookies = response.headers['set-cookie']
self.emailAddress = response.json().get('address')
def getEmailAddress(self) -> str:
return self.emailAddress
def getEmailCount(self) -> int:
"""Counts the number of emails in the inbox
Returns
-------
bool
the number of emails in the inbox
"""
response = rq.get(
'https://10minutemail.com/messages/messageCount',
headers = {'Cookie': self.cookies}
)
return response.json().get('messageCount')
def getAllEmails(self) -> list:
"""Gets all the emails in the inbox
Returns
-------
list
a list of all emails in the inbox
"""
emails = rq.get(
'https://10minutemail.com/messages/messagesAfter/0',
headers = {'Cookie': self.cookies}
)
return emails.json()
def getSecondsLeft(self) -> int:
"""Gets the remaining time in the email
Returns
-------
int
the number of seconds until the email expires
"""
response = rq.get(
'https://10minutemail.com/session/secondsLeft',
headers = {'Cookie': self.cookies}
)
return int(response.json().get('secondsLeft'))
def isExpired(self) -> bool:
"""Verifies if the session has expired
Returns
-------
bool
True if the session has expired and False otherwise
"""
response = rq.get(
'https://10minutemail.com/session/expired',
headers = {'Cookie': self.cookies}
)
return response.json().get('expired')
def refreshTime(self) -> bool:
"""Refreshes the duration of the email
Returns
-------
bool
True if the refresh was successfull and False otherwise
"""
response = rq.get(
'https://10minutemail.com/session/reset',
headers = {'Cookie': self.cookies}
)
return response.json().get('Response') == 'reset'