-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlask_Admin.py
More file actions
63 lines (50 loc) · 1.78 KB
/
Flask_Admin.py
File metadata and controls
63 lines (50 loc) · 1.78 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
from flask import Flask,render_template,url_for,redirect,request,session,flash
from flask.ext import superadmin
# Create custom admin view
class MyAdminView(superadmin.AdminIndexView):
@superadmin.expose('/')
def index(self):
return self.render('myadmin.html')
class ProxyAdminView(superadmin.BaseView):
@superadmin.expose('/',methods=['GET', 'POST'])
def index(self):
if request.method=="POST":
content = request.form['proxy']
with open('proxy.info','w') as fw:
fw.write(content)
else:
with open('proxy.info') as fr:
content = fr.read()
return self.render('proxy.html',data=content)
class CrawlAdminView(superadmin.BaseView):
@superadmin.expose('/',methods=['GET','POST'])
def index(self):
if request.method == 'POST':
url = request.form['url']
if url is None or url == '':
flash("The URL cant be empty!",'error')
else:
import subprocess
import os
os.system('cd /home/ubuntu/')
subprocess.call(['scrapy','version'], shell=True)
flash("Crawl the domain successuflly",'alert')
else:
url = ""
return self.render('crawl.html',url=url)
# Create flask app
app = Flask(__name__, template_folder='templates')
app.secret_key = 'my_secret'
# Flask views
@app.route('/')
def index():
return redirect('/admin/')
if __name__ == '__main__':
# Create admin interface
admin = superadmin.Admin(index_view=MyAdminView())
admin.add_view(CrawlAdminView(name="Crawl"))
admin.add_view(ProxyAdminView(name="Proxy"))
admin.init_app(app)
# Start app
app.debug = True
app.run(host='0.0.0.0',port=8080)