-
Notifications
You must be signed in to change notification settings - Fork 0
/
confWall.py
45 lines (37 loc) · 1.04 KB
/
confWall.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
import os
import http.server
import socketserver
def readFile(name = 'base.html'):
f = open(name, 'r')
data = f.read()
f.close()
return data
def writeFile(contents, name= 'index.html'):
f = open(name, 'w')
f.write(contents)
f.close()
def getPhotoList(path = 'pics'):
pics = os.listdir( os.path.join(os.path.dirname(__file__), path) )
pics2 = []
for pic in pics:
if pic != '.README':
pics2.append('"%s/%s"'% (path, pic))
return '[' + ','.join(pics2) + ']'
def confWall():
html = readFile()
images = getPhotoList()
newhtml = html.replace(
'<script></script>',
'<script>images = %s;</script>' % images
)
writeFile(newhtml)
if __name__ == '__main__':
confWall()
port = 8000
Handler = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", port), Handler) as httpd:
print("serving at port", port)
httpd.serve_forever()
print(f"serving at port {port}")
print("ctrl + c to quit")
httpd.serve_forever()