-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.py
83 lines (61 loc) · 1.94 KB
/
server.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
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import web
import process
import tikz
import email_pdf
class index:
def GET(self):
return 'Hello world'
class sample_image:
def POST(self):
web.header('Content-Type', 'image/jpeg')
x = web.input(uploadedfile={})
if 'uploadedfile' in x:
input_path = os.path.join('.', 'input-images', 'uploaded', x.uploadedfile.filename)
output_path = os.path.join('.', 'output-images', x.uploadedfile.filename)
print input_path, output_path
fout = open(input_path, 'w')
fout.write(x.uploadedfile.file.read())
fout.close()
shapes = process.prepare_img(input_path, output_path)
web.last_upload = shapes
print 'last_upload', web.last_upload
return open(output_path).read()
class save:
def GET(self):
if web.last_upload:
web.slides.append(web.last_upload)
print web.slides
else:
print 'No last upload'
return 'Success!'
class email_me:
def GET(self):
user_data = web.input()
if web.last_upload:
web.slides.append(web.last_upload)
print 'Rectifying'
rectified_slides = []
for (linear_shapes, ellipses) in web.slides:
img, rectified = \
process.prepare_rectified(None, linear_shapes, ellipses)
rectified_slides.append(rectified)
print 'Generating PDFs'
tikz.build_pdf(rectified_slides)
print 'Sending to email address ', user_data.email
email_pdf.send_pdf(user_data.email)
# print 'Clearing'
web.slides = []
web.last_upload = None
return 'Emailed!'
urls = (
'/', 'index',
'/sample_image', 'sample_image',
'/save', 'save',
'/email', 'email_me'
)
if __name__ == '__main__':
web.last_upload = None
web.slides = []
app = web.application(urls, globals())
app.run()