import logging import json from flask import (Flask, request, jsonify) from ltsdb_json import LTS logging.basicConfig(level=logging.DEBUG) app = Flask(__name__) log = logging.getLogger() @app.route("/") def home(): return jsonify({ "success": None }) @app.route("/report", methods=["POST"]) def report(): data = request.get_json() n_ts = 0 n_dp = 0 for d in data: d["description"]["remote_addr"] = request.remote_addr log.info("received %s", json.dumps(d)) ts = LTS(d["description"]) for dp in d["data"]: ts.add(*dp) ts.save() n_dp += 1 n_ts += 1 return jsonify({ "success": True, "timeseries": n_ts, "datapoints": n_dp })