#!/usr/bin/env python3
import flask
import subprocess

app = flask.Flask(__name__)

def show_frames():
    cmd = '''find data/frames/v5/*neg -name '*-qr.jpg' | sort -R | head -n 100'''
    lines = subprocess.check_output(cmd, shell=True).decode().splitlines()
    ret = '<div class="frames">'
    for line in lines:
        ret += f'<img src="{line}" />'
    ret += '</div>'
    return ret

@app.route('/')
def index():
    ret = '''
    <html>
    <head>
    <link rel="stylesheet" href="/data/css/style.css">
    </head>
    <body>
    '''
    ret += show_frames()

    ret += '''
    </body>
    </html>
    '''
    return ret

@app.route('/data/<path:path>')
def data(path):
    return flask.send_file('../data/' + path)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)