mpwebstatus / mpwebstatus /

# -*- coding: utf-8 -*-
from flask import Flask, request, render_template
import json
import time

app = Flask(__name__)

global datastore
datastore = {}

def index():
    return render_template("index.html")

@app.route("/update/<task>", methods=["POST"])
def update(task):
    data = json.loads(
    if task not in datastore:
        data["_born"] = data["_ping"] = time.time()
        data["_ping"] = time.time()
        data["_born"] = datastore[task]["_born"]
    datastore[task] = data
    return ""

def status():
    d = [{
        "task": k,
        "eta": v.get("eta", 0),
        "elapsed": (v.get("_ping", 0) if (v.get("finished", False) and v.get("_ping", 0)
            ) else time.time()) - v.get("_born", 0),
        "last_updated": time.time() - v.get("_ping", 0),
        "finished": v.get("finished", False),
        "progress": v.get("progress", 0),
        "total": v.get("total", 0),
        } for k, v in datastore.iteritems()]
    d.sort(key=lambda x: x["task"])
    return json.dumps(d)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.