def get_energy_imports():
    data = map(lambda x: {
        "id": str(x["id"]),
        "current_progress_point": x["thread"].importer.current_progress_point,
        "total_progress_points": x["thread"].importer.total_progress_points,
        "complete": x["thread"].importer.complete,
        "message": x["thread"].importer.message,
        "error": x["thread"].importer.error
    }, UploadsRepository.get_all())
    return json.dumps(data)
def upload_for_account(account_id):
    f = request.files["file"]
    if f:
        try:
            newfile = tempfile.TemporaryFile()
            buf = f.stream.read(1024)
            while len(buf):
                newfile.write(buf)
                buf = f.stream.read(1024)
            f.stream.close()
            newfile.seek(0)
            import_id = UploadsRepository.start_import(account_id, newfile, "duke")
            return jsonify({"id": import_id})
        except Exception as e:
            abort(500)
    else:
        abort(400)