from urllib import request from flask import Flask, jsonify, render_template, url_for, request, redirect import json import datetime from pymongo import MongoClient CONNECTION_STRING = "mongodb://mongodb:Cc03Wz5XX3iI3uY3@mongo" db_connection = MongoClient(CONNECTION_STRING) db_base = db_connection["phone"] coll_call = db_base["phone"] coll_history = db_base["history"] app = Flask(__name__) internal = {} external = {} State = "" findLimit = 200 @app.route("/") def root(): return "Ok" IgnoreList = ['83919865589', '83912051046', '83912051045', '84950213944', '84951252791', '83919865589', '84951183750', '89919237009', '89919241441', '89919863883', '89919505445', '89919398228', '89919500798'] @app.route("/web/call/") def WebCall(): call = coll_call.find().limit(findLimit).sort('time', -1) return render_template("WebCall.html", call=call) @app.route("/web/call/test/") def GetTest(): call = coll_call.find({'client': {'$nin': IgnoreList}}).limit(findLimit).sort('time', -1) return render_template("TestCall.html", call=call) @app.route("/web/call/test/") def GetTestId(id): call = coll_call.find( {'client': {'$nin': IgnoreList}, 'status': int(id)}).sort('time', -1) return render_template("TestCall.html", call=call) @app.route("/web/call/status/") def WebCallStatus(id): call = coll_call.find({"status": int(id)}).sort('time', -1) call = coll_call.find( {'client': {'$nin': IgnoreList}, 'status': int(id)}).limit(findLimit).sort('time', -1) return render_template("WebCall.html", call=call) @app.route("/web/call/find/", methods=["GET"]) def WebCallFind(): try: id = str(request.args.get("client")) call = coll_call.find({"client": {"$regex": str(id)}}).limit(findLimit).sort('time', -1) return(render_template("WebCall.html", call=call)) except Exception as e: return(str(e)) if __name__ == "__main__": app.debug = True app.run(host="0.0.0.0", port=5001)