Created
March 19, 2021 07:40
-
-
Save moinologics/692c503382ef29c565fbf6a3eb200281 to your computer and use it in GitHub Desktop.
python class for 1secmail.com
This file contains hidden or 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 as http | |
class OneSecMail(): | |
"""class for 1secmail.com api""" | |
def __init__(self,http_timeout=5): | |
self.base_url = 'https://www.1secmail.com/api/v1/' | |
self.http_timeout_sec = http_timeout | |
def __fetch(self,url): | |
"""a private utility function for http request""" | |
try: | |
r = http.get(url,timeout=self.http_timeout_sec) | |
if r.status_code == 200: | |
return r | |
except Exception as e: | |
print(str(e)) | |
return False | |
def generate_emails(self,count=1): | |
url = '{}?action=genRandomMailbox&count={}'.format(self.base_url,count) | |
resp = self.__fetch(url) | |
if resp: | |
return resp.json() | |
else: | |
return [] | |
def check_emails(mail_addr): | |
mail_user,mail_domain = mail_addr.split('@') | |
url = '{}?action=getMessages&login={}&domain={}'.format(self.base_url,mail_user,mail_domain) | |
resp = self.__fetch(url) | |
if resp: | |
return resp.json() | |
else: | |
return [] | |
def read_email(mail_addr,msg_id): | |
url = '{}?action=readMessage&login={}&domain={}&id={}'.format(self.base_url,mail_user,mail_domain,msg_id) | |
resp = self.__fetch(url) | |
if resp: | |
return resp.json() | |
else: | |
return [] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment