Created
July 1, 2021 18:22
-
-
Save williangl/705689e205b6aca37181ec59f0357858 to your computer and use it in GitHub Desktop.
get code from email
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
"""Modulo de email temporário.""" | |
from parsel import Selector | |
from httpx import get | |
base_url = 'https://www.1secmail.com/api/v1/' | |
def split_email_account(email_account: str) -> tuple: | |
username, domain = email_account.split('@') | |
return username, domain | |
def get_emails_from_account(email_account: str) -> dict: | |
username, domain = split_email_account(email_account) | |
emails = get( | |
f'{base_url}?action=getMessages&login={username}&domain={domain}' | |
) | |
return emails.json() | |
def get_latest_received_email_id(emails_content: dict) -> str: | |
return emails_content[0]["id"] | |
def read_email_content(email_account: str, email_id: str) -> dict: | |
username, domain = split_email_account(email_account) | |
email_content = get( | |
f"{base_url}?action=readMessage&login={username}&domain={domain}&id={email_id}" | |
) | |
return email_content.json() | |
def get_code_from_email_content(email_content: dict) -> str: | |
s = Selector(text=email_content["body"]) | |
code = s.css('strong::text').get() | |
return code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment