Skip to content

Instantly share code, notes, and snippets.

@5S
Created January 31, 2019 17:11
Show Gist options
  • Save 5S/a60aeb5b352d77215d82315c0b417780 to your computer and use it in GitHub Desktop.
Save 5S/a60aeb5b352d77215d82315c0b417780 to your computer and use it in GitHub Desktop.
temp-mail.org で利用できる捨てアドサービスの API ラッパー
# -*- coding: utf-8 -*-
import hashlib
import json
import requests
import random
import string
class TempMail:
def __init__(self):
self.session = requests.Session()
self.mashape_key = 'YOUR MASHAPE KEY'
self.domains_list = self.get_domains_list()
self.mail_address = self.get_mail_address()
self.mail_address_md5 = hashlib.md5(self.mail_address.encode('utf-8')).hexdigest()
def get_domains_list(self):
res = self.session.get('https://privatix-temp-mail-v1.p.mashape.com/request/domains/', headers={'X-Mashape-Key': self.mashape_key, 'Accept': 'application/json'})
return json.loads(res.text)
def get_mail_address(self):
mail = self.randstr(8)
domain = self.domains_list[random.randint(0, len(self.domains_list)) - 1]
return mail + domain
def change_mail_address(self, new_mail_address):
self.mail_address = new_mail_address
self.mail_address_md5 = hashlib.md5(new_mail_address.encode('utf-8')).hexdigest()
def get_emails(self):
res = self.session.get(f'https://privatix-temp-mail-v1.p.mashape.com/request/mail/id/{self.mail_address_md5}/', headers={'X-Mashape-Key': self.mashape_key, 'Accept': 'application/json'})
return json.loads(res.text)
def get_one_message(self, mail_id):
res = self.session.get(f'https://privatix-temp-mail-v1.p.mashape.com/request/mail/id/{mail_id}/', headers={'X-Mashape-Key': self.mashape_key, 'Accept': 'application/json'})
return json.loads(res.text)
def get_source_message(self, mail_id):
res = self.session.get(f'https://privatix-temp-mail-v1.p.mashape.com/request/source/id/{mail_id}/', headers={'X-Mashape-Key': self.mashape_key, 'Accept': 'application/json'})
return json.loads(res.text)
def get_message_attachments(self, mail_id):
res = self.session.get(f'https://privatix-temp-mail-v1.p.mashape.com/request/attachments/id/{mail_id}/', headers={'X-Mashape-Key': self.mashape_key, 'Accept': 'application/json'})
return json.loads(res.text)
def delete_message(self, mail_id):
res = self.session.get(f'https://privatix-temp-mail-v1.p.mashape.com/request/delete/id/{mail_id}/', headers={'X-Mashape-Key': self.mashape_key, 'Accept': 'application/json'})
return json.loads(res.text)
def randstr(self, n):
randlst = [random.choice(string.ascii_lowercase) for i in range(n)]
return ''.join(randlst)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment