-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (47 loc) · 1.36 KB
/
main.py
File metadata and controls
64 lines (47 loc) · 1.36 KB
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
# -*- coding:UTF-8 -*-
from flask import Flask, render_template, request, abort, jsonify, redirect
import requests
import random
app = Flask(__name__)
@app.route('/') #访问根目录默认页执行home()
def home():
return render_template('home.html', resp=None)
@app.route('/api')
def api():
return jsonify({'name': 'etf', 'version': '0.01'})
@app.route('/error')
def error():
codes = [404, 401, 403, 500]
random.shuffle(codes)
abort(codes[0])
@app.route('/handle_get', methods=['POST'])
def handle_get():
url = request.form['url']
assertion = request.form['assert']
assertion_success = None
try:
r = requests.get(url)
if assertion is not None and assertion != '':
obj = r.json()
if assertion:
assertion_success = eval(assertion)
except Exception as e:
print(e)
r = None
resp = build_resp(r)
resp['assertion'] = assertion
resp['assertion_success'] = assertion_success
return render_template('home.html', resp=resp)
def build_resp(r):
resp = {'success': False}
if r is None:
return resp
if r.status_code < 400:
resp['success'] = True
resp['url'] = r.url
resp['text'] = r.text
resp['headers'] = r.headers
resp['status_code'] = r.status_code
return resp
if __name__ == '__main__':
app.run()