-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend.py
51 lines (42 loc) · 894 Bytes
/
backend.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
import web
import json
import os
urls = (
'/', 'index',
'/data/', 'data',
'/images/(.*)', 'images'
)
class index:
def GET(self):
index = open('index.html', 'r')
return index
class data:
def GET(self):
data = open('mom_data.json', 'r')
return data
def POST(self):
data = web.data()
with open('mom_data.json', 'a') as file:
file.seek(-1, os.SEEK_END)
file.truncate()
file.write(',')
file.write(data)
file.write(']')
return data
class images:
def GET(self, name):
ext = name.split(".")[-1]
cType = {
"png" : "images/png",
"jpg" : "images/jpg",
"gif" : "images/gif",
"ico" : "images/x-icon"
}
if name in os.listdir('images'):
web.header("Content-Type", cType[ext])
return open('images/{0}'.format(name),"rb").read()
else:
raise web.notfound()
if __name__ == "__main__":
app = web.application(urls, globals())
app.run()