-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (43 loc) · 1.08 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
import os
from markupsafe import escape
from flask import (
Flask,
render_template,
url_for,
request,
session,
redirect
)
from whois.query import Whois
import config
app = Flask(__name__)
app.secret_key = os.getenv('API_KEY')
@app.route('/lookup', methods=['POST'])
def whois_lookup():
dname = request.form.get('dname')
session['errors'] = ''
session['whoisInfo'] = ''
if not dname:
return redirect(url_for('index'), code=302)
whois = Whois(dname)
try:
data = whois.request()
except Exception:
data = ''
if not data:
session['errors'] = config.WRONG_DATA
else:
session['whoisInfo'] = data
return redirect(url_for('index'), code=302)
@app.route('/', methods=['GET'])
def index():
static = url_for('static', filename='style.css')
js_script = url_for('static', filename='main.js')
data = {
'static': static,
'script': js_script,
'result': session
}
return render_template('index.html', **data)
if __name__ == '__main__':
app.run(debug=True)