Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions html/index.html

This file was deleted.

51 changes: 0 additions & 51 deletions html/js/main.js

This file was deleted.

7 changes: 0 additions & 7 deletions html/js/vendor/bootstrap.min.js

This file was deleted.

5 changes: 0 additions & 5 deletions html/js/vendor/jquery-1.12.0.min.js

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
flask
56 changes: 30 additions & 26 deletions shotit
Original file line number Diff line number Diff line change
@@ -1,41 +1,45 @@
#!/usr/bin/env python3
#!/usr/bin/env python

import glob
import json
from flask import Flask, render_template, send_from_directory, Response
from glob import glob
import os
import sys
import time

import http.server
app = Flask(__name__)

HTTP_SERVER_HOST = "localhost"
HTTP_SERVER_PORT = 8888
imgdir = sys.argv[1]
SUFFIXES = ['gif', 'jpg', 'png']


def description(path):
desc_path = os.path.splitext(path)[0] + ".txt"
with open(desc_path, 'r') as f:
return f.read()
@app.route('/')
def index():
images = sum([glob("%s/*.%s" % (imgdir, s)) for s in SUFFIXES], [])
return render_template('base.html',
images=[os.path.basename(i) for i in images])


def main():
rundir = sys.argv[1]
output_file = rundir + "/" + "gallery_items.json"
def event_stream():
mtime = os.path.getmtime(imgdir)
# TODO: eliminate polling
while True:
time.sleep(1)
new_mtime = os.path.getmtime(imgdir)
if new_mtime != mtime:
mtime = new_mtime
yield 'data: please reload\n\n'

images = glob.glob(rundir + "/*.png")
images.extend(glob.glob(rundir + "/*.gif"))
images.extend(glob.glob(rundir + "/*.jpg"))
images.sort()

gallery_items = [{"img_path": os.path.split(img)[1], "description": description(img)} for img in images]
with open(output_file, 'w') as outfile:
json.dump(gallery_items, outfile, separators=(',', ':'))
@app.route('/stream')
def stream():
return Response(event_stream(), mimetype="text/event-stream")

os.system("cp -r html/* " + rundir)

os.chdir(rundir)
httpd = http.server.HTTPServer((HTTP_SERVER_HOST, HTTP_SERVER_PORT), http.server.SimpleHTTPRequestHandler)
print("HTTP server opened at %s:%d" % (HTTP_SERVER_HOST, HTTP_SERVER_PORT))
httpd.serve_forever()
@app.route('/<path:path>')
def any(path):
return send_from_directory(imgdir, path)


if __name__ == "__main__":
main()
app.debug = True
app.run(threaded=True, port=8888)
19 changes: 19 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<html>
<head>
<title>Test</title>
</head>

<script>
var source = new EventSource('/stream');
source.onmessage = function (event) {
location.reload();
};
</script>

<body>
<h1>All the nice pages</h1>
{% for image in images %}
<img src="{{image}}"/>
{% endfor %}
</body>
</html>