-
Notifications
You must be signed in to change notification settings - Fork 11
/
webserver.py
34 lines (28 loc) · 924 Bytes
/
webserver.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
import subprocess
from flask import Flask, request, Response
server = Flask(__name__)
SINGLEFILE_EXECUTABLE = '/node_modules/single-file/cli/single-file'
BROWSER_PATH = '/opt/google/chrome/google-chrome'
BROWSER_ARGS = '["--no-sandbox"]'
@server.route('/', methods=['POST'])
def singlefile():
url = request.form.get('url')
if url:
p = subprocess.Popen([
SINGLEFILE_EXECUTABLE,
'--browser-executable-path=' + BROWSER_PATH,
"--browser-args='%s'" % BROWSER_ARGS,
request.form['url'],
'--dump-content',
],
stdout=subprocess.PIPE)
else:
return Response('Error: url parameter not found.',
status=500)
singlefile_html = p.stdout.read()
return Response(
singlefile_html,
mimetype="text/html",
)
if __name__ == '__main__':
server.run(host='0.0.0.0', port=80)