Skip to content

Instantly share code, notes, and snippets.

@williangl
Created July 1, 2021 18:22
Show Gist options
  • Save williangl/705689e205b6aca37181ec59f0357858 to your computer and use it in GitHub Desktop.
Save williangl/705689e205b6aca37181ec59f0357858 to your computer and use it in GitHub Desktop.
get code from email
"""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