-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
91 lines (71 loc) · 2.07 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
from flask import Flask, jsonify, redirect, url_for
from flask_limiter.util import get_remote_address
from flask_limiter import Limiter
from dotenv import dotenv_values
from Helpers import Email as EmailHelper
config = dotenv_values(".env")
app = Flask(__name__)
limiter = Limiter(
app,
key_func=get_remote_address,
default_limits=["5000 per day", "50 per minute"],
storage_uri="memory://",
)
mailbox = EmailHelper.Email()
mailbox.Login()
def index_error_responder(request_limit):
return jsonify(
{
"status": "error",
"message": "You have reached the request limit of {} requests per day".format(
request_limit.limit
),
}
)
@app.route('/read/<email>', methods=['GET'])
@limiter.limit("20/minute", on_breach=index_error_responder)
def get_message(email):
return jsonify(mailbox.GetMessages(email))
@app.route('/delete/<uid>', methods=['GET'])
def delete_message(uid):
return jsonify(mailbox.delete_message(uid))
@app.route('/readby/<email>/<string_data>', methods=['GET'])
@limiter.limit("20/minute", on_breach=index_error_responder)
def read_by(email, string_data):
if string_data is None:
return jsonify(
{
'status': False,
'message': 'Data Search is empty'
}
)
else:
return jsonify(mailbox.read_by(string_data, email))
@app.route('/', methods=['GET'])
def index():
return jsonify(
{
'status': True,
'message': 'Welcome to API'
}
)
@app.route('/generate/<type>', methods=['GET'])
def generate_email(type):
# Gmail Dot Trick Refrence
#
# https://codegolf.stackexchange.com/questions/204473/generate-gmail-dot-aliases
return jsonify(
{
'status': True,
'message': 'Success',
'data': mailbox.generate_email(type)
}
)
@app.errorhandler(404)
def not_found(error):
return redirect(url_for('index'))
if __name__ == "__main__":
app.run(
host='0.0.0.0',
threaded=True,
)