Created
November 1, 2021 00:52
-
-
Save TheEpicFace007/def6068fbb181db365388b27d1d1ea4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#%% | |
import requests, numpy as np | |
from typing import TypedDict | |
#%% | |
EMail = TypedDict("EMail", | |
{ | |
"id": str, | |
"sender": str, | |
"subject": str, | |
"sendDateFormated": str, | |
"bodyPlainText": str, | |
"bodyHtmlContent": str | |
}) | |
TenMinbuteMailError = TypedDict("TenMinbuteMailError", { | |
"timestamp": str, | |
"status": int, | |
"error": str, | |
"messages": str, | |
"path": str | |
}) | |
class TenMinuteMail: | |
def __init__(self) -> None: | |
self.base_url = "https://10minutemail.com" | |
self.session = requests.Session() | |
self.get_email() | |
def get_email(self): | |
address_response = self.session.get(f"{self.base_url}/session/address") | |
self.email: str = address_response.json()["address"] | |
return self.email | |
def get_seconds_left(self): | |
data = self.session.get(f"{self.base_url}/session/secondsLeft") | |
return data.json()["secondsLeft"] | |
def has_expired(self): | |
data = self.session.get(f"{self.base_url}/session/expired") | |
return data.json().expired | |
def get_msg(self, index: int): | |
data = self.session.get(f"{self.base_url}/messages/messagesAfter/{index}").json() | |
try: | |
data["error"] | |
err: TenMinbuteMailError = data | |
return err | |
except: | |
result: list[EMail] = data | |
return result | |
def get_msg_count(self): | |
data = self.session.get(f"{self.base_url}/messages/messagesCount") | |
try: | |
msg_count: int = data["messagesCount"] | |
return msg_count | |
except: | |
err: TenMinbuteMailError = data | |
return err | |
def get_10_minute(self): | |
self.session.get(f"{self.base_url}/session/reset") | |
def reply_to_msg(self, msg_id: str, reply_content: str): | |
data = self.session.post(f"/messages/reply", json={ | |
"Reply": { "messageId": msg_id, "replyBody": reply_content } | |
}, headers={"Accept": "application"}) | |
return data.json() | |
def forward_msg(self, msg_id: str, forward_address: str): | |
data = self.session.post(f"{self.base_url}/messages/reply", json={ | |
"Forward": { "messageId": msg_id, "forwardAddress": forward_address } | |
}, headers={"Accept": "application"}) | |
return data.json() | |
# %% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment