2024-02-20 16:43:56 +07:00

76 lines
2.1 KiB
Python

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-dev"]
coll = db_base["phone"]
rep = False
# coll_call = db_base["phone"]
# coll_history = db_base["history"]
app = Flask(__name__)
internal = {}
external = {}
State = ""
Findlimit = 100
@app.route("/")
def root():
return redirect("/notanswer")
IgnoreList = ['83919865589', '83912051046', '83912051045', '84950213944', '84951252791', '83919865589',
'84951183750', '89919237009', '89919241441', '89919863883', '89919505445', '89919398228', '89919500798']
ImportantNumber = ['839122051045']
@app.route("/answer")
def answer():
call = coll.find({"status": "ANSWERED"}).sort('time', -1).limit(Findlimit)
return render_template("answer.html", call=call) if rep == False else render_template("repair.html")
@app.route("/notanswer")
def notanswer():
call = coll.find({"status": "NOT_ANSWERED"}).sort(
'time', -1).limit(Findlimit)
return render_template("notanswer.html", call=call) if rep == False else render_template("repair.html")
@app.route("/truerecall")
def recallTrue():
call = coll.find({"status": "RECALL_TRUE"}).sort(
'time', -1).limit(Findlimit)
return render_template("truerecall.html", call=call) if rep == False else render_template("repair.html")
@app.route("/falserecall")
def rcallFalse():
call = coll.find({"status": "RECALL_FALSE"}).sort(
'time', -1).limit(Findlimit)
return render_template("falserecall.html", call=call) if rep == False else render_template("repair.html")
# API
@app.route("/api/v1/call/set/", methods=["POST"])
def call_put():
print(request.form)
if request.form["act"] == "delete":
coll.update_one({"uuid": request.form["uuid"]}, {
"$set": {"status": "DELETED"}})
return redirect("/falserecall")
if __name__ == "__main__":
app.debug = True
app.run(host="0.0.0.0", port=6001)