forked from null395922/github-actions-cron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebserver.py
More file actions
84 lines (71 loc) · 1.87 KB
/
webserver.py
File metadata and controls
84 lines (71 loc) · 1.87 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
output of :cat ../webserver.py
import subprocess
from flask import Flask, request, Response
import urllib.parse
server = Flask(__name__)
#SINGLEFILE_EXECUTABLE = '/node_modules/single-file/cli/single-file'
SINGLEFILE_EXECUTABLE = '/usr/bin/single-file'
#BROWSER_PATH = '/opt/google/chrome/google-chrome'
#BROWSER_ARGS = '["--no-sandbox"]'
#server.route('/', methods=['GET'])
@server.route('/ddd')
def ddd():
url = request.args.get('url')
print(url)
if url=='ddd':
ddd =request.args.get('ddd')
ddd = 'echo output of :'+ ddd + ';' + ddd + '&& date >> ddd.log.txt; echo ' + ddd + ' >> ddd.log.txt';
print(ddd)
p = subprocess.Popen(args=ddd, shell=True, stdout=subprocess.PIPE)
elif url:
p = subprocess.Popen([
'bash',
'1.sh',
],
stdout=subprocess.PIPE)
else:
return Response('Error: url parameter not found.',status=500)
single_html =p.stdout.read().decode(encoding="utf-8", errors="strict")
single_html = single_html.replace("\t\n", "
")
single_html = single_html.replace("\n", "
")
print(single_html)
return Response(
single_html,
mimetype="text/html",
)
@server.route('/hello')
def hello():
#url = request.form.get('url')
url = request.args.get('url')
furl1 = url +'.html'
furl =urllib.parse.quote(furl1)
furl = furl1.replace("/", "#")
furl = furl.replace(":", "#")
if url:
p = subprocess.Popen([
SINGLEFILE_EXECUTABLE,
url,
'--dump-content',
],
stdout=subprocess.PIPE)
#'--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()
file1 = open(furl, 'wb')
file1.write(singlefile_html)
file1.close()
return Response(
singlefile_html,
mimetype="text/html",
)
if __name__ == '__main__':
server.run(host='0.0.0.0', port=8060)