-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
82 lines (73 loc) · 2.05 KB
/
app.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
import traceback
from flask import Flask, request
import re
import hashlib
import smtplib
import requests
import json
from flask_cors import CORS
usr = "[email protected]"
pswd = "Apakah?##5"
app = Flask(__name__)
CORS(app)
@app.route("/")
def home():
return "Home"
@app.route("/check/<string>")
def checker(string):
# get path parameter called string with Flask
md5 = str(request.view_args['string'])
matched = re.match(r"[a-f0-9]{32}", md5)
print(matched)
print(md5)
if matched != None:
return str(matched.group() == md5)
else:
return "False"
@app.route("/gen/<string>")
def generator(string):
# get query parameter called string
string = request.view_args['string']
# convert string to md5 using hashlib
md5 = hashlib.md5(string.encode('utf-8')).hexdigest()
return str(md5)
@app.route("/sendEmail")
def sendEmail():
# get query parameter called name
name = request.args.get('name')
email = request.args.get('email')
message = request.args.get('message')
url = "https://rapidprod-sendgrid-v1.p.rapidapi.com/mail/send"
payload = {
"personalizations": [
{
"to": [
{
"email": "[email protected]"
}
],
"subject": "MD5 Contact"
}
],
"from": {
"email": email
},
"content": [
{
"type": "text/plain",
"value": f"Name: {name}\nEmail: {email}\n\n{message}"
}
]
}
headers = {
'content-type': "application/json",
'x-rapidapi-host': "rapidprod-sendgrid-v1.p.rapidapi.com",
'x-rapidapi-key': "8ee4a2a0ebmshc758cdfc9769e70p1c9e26jsn710476d3e649"
}
response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
if response.status_code == 202:
print('e')
return "Email sent!"
else:
print(traceback.format_exc())
return "Something went wrong!"