-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
71 lines (57 loc) · 2.38 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
59
60
61
62
63
64
65
66
67
68
69
70
# App code goes there.
from flask import Flask, jsonify, session
def del_waste(self, wastes):
waste = ['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
'__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'build', 'run', 'generate',]
production = []
for i in wastes:
j = getattr(self, i)
if i not in waste and hasattr(j, "litchi") == True:
production.insert(0, j)
return production
class App:
def generate(self, model):
elements = self.build() if self.build() != None else del_waste(self, dir(self))
# 如有返回,使用返回顺序
# print(elements)
requires = ""
for element in elements:
if hasattr(element,"require"):
requires += element.require
html_begin = '''
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<script type="text/javascript"
src="https://cdn.jsdelivr.net/npm/[email protected]/brython.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>
<link href="https://cdn.bootcdn.net/ajax/libs/pure/2.0.3/pure-min.css" rel="stylesheet">
{require}
</head>
<body onload="brython()">
'''.format(require=requires)
# To use Brython,use<script type="text/python">You code</script>
for element in elements:
html_begin += element.convert()
html = html_begin + '''
</body>
</html>
'''
if model== "static":
return html
elif model=="server":
self.app = Flask(__name__)
@self.app.route('/',methods=['GET','POST'])
def web():
return html
@self.app.route('/ajax/<id>/<event>', methods=['POST','GET'])
def ajax(id, event):
for element in elements:
if element.id == id:
if event == 'click':
return jsonify(element.on_pressed())
return self.app
def run(self, **args):
self.generate("server").run(**args)