118 lines
3.2 KiB
Python
118 lines
3.2 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
|
|
import requests
|
|
|
|
CONNECTION_STRING = "mongodb://mongodb:Cc03Wz5XX3iI3uY3@mongo"
|
|
|
|
db_connection = MongoClient(CONNECTION_STRING)
|
|
db_base = db_connection["phone-dev"]
|
|
coll = db_base["phone"]
|
|
bl = db_base["blacklist"]
|
|
|
|
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")
|
|
|
|
|
|
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")
|
|
|
|
|
|
@app.route("/blacklist")
|
|
def blacklist():
|
|
call = bl.find().sort('_id')
|
|
return render_template("blacklist.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_many({"uuid": request.form["uuid"], "status": "RECALL_FALSE"}, {
|
|
"$set": {"status": "DELETED"}})
|
|
return redirect("/falserecall")
|
|
|
|
|
|
@app.route("/api/v1/blacklist/add/<number>", methods=["POST"])
|
|
def blacklist_put(number):
|
|
insdict = {"_id": number, "desc": datetime.datetime.now()}
|
|
bl.update_one({"_id": number}, {"$set": insdict}, True)
|
|
coll.update_many({"client": number, "status": {
|
|
"$in": ["RECALL_TRUE", "RECALL_FALSE", "NOT_ANSWERED"]}}, {"$set": {"status": "IGNORED"}})
|
|
return redirect("/blacklist")
|
|
|
|
|
|
@app.route("/api/v1/blacklist/delete/<number>", methods=["POST"])
|
|
def blacklist_delete(number):
|
|
bl.delete_many({"_id": number})
|
|
return redirect("/blacklist")
|
|
|
|
|
|
@app.route("/api/v1/blacklist/get/<number>")
|
|
def blacklist_get(number):
|
|
try:
|
|
return [i for i in bl.find({"_id": number})][0]
|
|
except:
|
|
return {}
|
|
|
|
|
|
@app.route("/api/v1/sync")
|
|
def sync():
|
|
j = []
|
|
for x in coll.find({"status": "NOT_ANSWERED"}):
|
|
t_req = "https://callinfo.services.mobilon.ru/api/call/info/1e86a98e026578eb5f6bf8c092c0c4a2/" + \
|
|
x["uuid"]
|
|
res: dict = json.loads(requests.get(t_req).content)
|
|
|
|
j.append(res)
|
|
coll.update_one({"uuid": x["uuid"]}, {"$set": res})
|
|
return j
|
|
|
|
|
|
if __name__ == "__main__":
|
|
app.debug = True
|
|
app.run(host="0.0.0.0", port=6001)
|