-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·88 lines (78 loc) · 2.08 KB
/
main.py
File metadata and controls
executable file
·88 lines (78 loc) · 2.08 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
85
86
87
88
import os
from google.appengine.ext.webapp import template
import cgi
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
nodes = {}
adj = {}
adj_arg = {}
i = 0
colors = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
def color(arg):
global colors
colored = {}
for color in colors:
colored[color] = []
color = 0
for node,neigh in arg.items():
while 1:
flag = 1
a = sorted(neigh)
for i in a:
if i in colored[ colors[color] ]:
color += 1
flag = 0
break
if flag:
colored[ colors[color] ].append(node)
color = 0
break
return colored
class MainHandler(webapp.RequestHandler):
def get(self):
template_values = {}
path = os.path.join(os.path.dirname(__file__), 'main.html')
self.response.out.write(template.render(path, template_values))
def post(self):
global values
global i
global adj
global adj_arg
d = [0, 0, 0]
template_values = {}
counter = 0
res = cgi.escape(self.request.get(str(counter)))
if res == 'create':
counter += 1
d[counter - 1] = int(cgi.escape(self.request.get(str(counter))))
counter += 1
d[counter - 1] = int(cgi.escape(self.request.get(str(counter))))
elif res == 'select':
a = int(cgi.escape(self.request.get(str(counter + 1))))
b = int(cgi.escape(self.request.get(str(counter + 2))))
try:
if b not in adj[a]:
adj[a].append(b)
if b not in adj_arg[a]:
adj_arg[a].append(b)
if a not in adj_arg[b]:
adj_arg[b].append(a)
except KeyError:
pass
if res == 'create':
nodes[i] = d
adj[i] = [] # Initialize adjacency list
adj_arg[i] = [] # Initialize adjacency list
i += 1
colr = color(adj_arg)
template_values['cord'] = nodes
template_values['adj'] = adj
template_values['color'] = colr
path = os.path.join(os.path.dirname(__file__), 'main.html')
self.response.out.write(template.render(path, template_values))
def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()