repair functions
This commit is contained in:
parent
85dda3de3c
commit
9518a916a6
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
**/.venv
|
**/.venv
|
||||||
**/.vscode
|
**/venv
|
||||||
|
**/.vscode
|
||||||
|
27
web/app.py
27
web/app.py
@ -16,7 +16,7 @@ app = Flask(__name__)
|
|||||||
internal = {}
|
internal = {}
|
||||||
external = {}
|
external = {}
|
||||||
State = ""
|
State = ""
|
||||||
findLimit = 1000
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def root():
|
def root():
|
||||||
@ -32,20 +32,27 @@ def WebCall():
|
|||||||
call = coll_call.find().limit(findLimit).sort('time', -1)
|
call = coll_call.find().limit(findLimit).sort('time', -1)
|
||||||
return render_template("WebCall.html", call=call)
|
return render_template("WebCall.html", call=call)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/web/call/test/")
|
||||||
|
def GetTest():
|
||||||
|
call = coll_call.find({'client': {'$nin': IgnoreList}}).sort('time', -1)
|
||||||
|
return render_template("TestCall.html", call=call)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/web/call/test/<id>")
|
||||||
|
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/<id>")
|
@app.route("/web/call/status/<id>")
|
||||||
def WebCallStatus(id):
|
def WebCallStatus(id):
|
||||||
|
call = coll_call.find({"status": int(id)}).sort('time', -1)
|
||||||
call = coll_call.find(
|
call = coll_call.find(
|
||||||
{'client': {'$nin': IgnoreList}, 'status': int(id)}).limit(findLimit).sort('time', -1)
|
{'client': {'$nin': IgnoreList}, 'status': int(id)}).sort('time', -1)
|
||||||
return render_template("WebCall.html", call=call)
|
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__":
|
if __name__ == "__main__":
|
||||||
app.debug = True
|
app.debug = True
|
||||||
|
@ -42,29 +42,6 @@ a {
|
|||||||
}
|
}
|
||||||
|
|
||||||
header {
|
header {
|
||||||
height: 80px;
|
height: 50px;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
}
|
|
||||||
|
|
||||||
.search {
|
|
||||||
height: 30px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search_label {
|
|
||||||
color: chocolate;
|
|
||||||
font-family: Verdana, Geneva, Tahoma, sans-serif;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search_text {
|
|
||||||
color: chocolate;
|
|
||||||
font-family: Verdana, Geneva, Tahoma, sans-serif;
|
|
||||||
font-weight: bold;
|
|
||||||
width: 200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.search_btn {
|
|
||||||
color: chocolate;
|
|
||||||
font-family: Verdana, Geneva, Tahoma, sans-serif;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
@ -12,34 +12,21 @@
|
|||||||
<a href="/web/call/status/0">Входящий вызов принят</a>
|
<a href="/web/call/status/0">Входящий вызов принят</a>
|
||||||
<a href="/web/call/status/1">Входящий вызов не принят</a>
|
<a href="/web/call/status/1">Входящий вызов не принят</a>
|
||||||
<a href="/web/call/status/2">Перезвонили</a>
|
<a href="/web/call/status/2">Перезвонили</a>
|
||||||
|
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
<form name="search" action="/web/call/find/" method="get">
|
|
||||||
<label>Поиск</label>
|
|
||||||
<input type="text" name="client" value="">
|
|
||||||
<input type="submit" title="Найти">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Номер клиента</td>
|
<td>Номер клиента</td>
|
||||||
<!-- <td>Номер оператора</td> -->
|
<!-- <td>Номер оператора</td> -->
|
||||||
<td>Дата время события</td>
|
<td>Дата время</td>
|
||||||
<td>Ссылка на запись</td>
|
<td>Ссылка на запись</td>
|
||||||
|
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
{% for entry in call %}
|
{% for entry in call %}
|
||||||
<tr>
|
<tr>
|
||||||
<!-- <td>{{ entry.client }}</td> -->
|
<!-- <td>{{ entry.client }}</td> -->
|
||||||
{% if entry.important == True %}
|
<td><a href="tel:{{ entry.client }}">{{ "%s %s %s %s"|format(entry.client[0:1], entry.client[1:4], entry.client[4:7], entry.client[7:11]) }}</a></td>
|
||||||
<td><font color="#C30000">{{ "%s %s %s %s"|format(entry.client[0:1], entry.client[1:4], entry.client[4:7], entry.client[7:11]) }}</font></td>
|
|
||||||
{% else %}
|
|
||||||
<td >{{ "%s %s %s %s"|format(entry.client[0:1], entry.client[1:4], entry.client[4:7], entry.client[7:11]) }}</td>
|
|
||||||
{% endif %}
|
|
||||||
<!-- <td>{{ entry.Operator }}</td> -->
|
<!-- <td>{{ entry.Operator }}</td> -->
|
||||||
<td>{{ entry.time }}</td>
|
<td>{{ entry.time }}</td>
|
||||||
<td>
|
<td>
|
@ -11,6 +11,7 @@
|
|||||||
<header>
|
<header>
|
||||||
<a href="/web/call/status/0">Входящий вызов принят</a>
|
<a href="/web/call/status/0">Входящий вызов принят</a>
|
||||||
<a href="/web/call/status/1">Входящий вызов не принят</a>
|
<a href="/web/call/status/1">Входящий вызов не принят</a>
|
||||||
|
<<<<<<< HEAD
|
||||||
<a href="/web/call/status/2">Перезвонили успешно</a>
|
<a href="/web/call/status/2">Перезвонили успешно</a>
|
||||||
<a href="/web/call/status/4">Перезвонили безуспешно</a>
|
<a href="/web/call/status/4">Перезвонили безуспешно</a>
|
||||||
<p>
|
<p>
|
||||||
@ -20,12 +21,16 @@
|
|||||||
<input class="search_btn" type="submit" title="Найти">
|
<input class="search_btn" type="submit" title="Найти">
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
|
=======
|
||||||
|
<a href="/web/call/status/2">Перезвонили</a>
|
||||||
|
|
||||||
|
>>>>>>> parent of c52dc73 (Добавил поиск)
|
||||||
</header>
|
</header>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Номер клиента</td>
|
<td>Номер клиента</td>
|
||||||
|
<!-- <td>Номер оператора</td> -->
|
||||||
<td>Дата время</td>
|
<td>Дата время</td>
|
||||||
<td>Статус звонка</td>
|
|
||||||
<td>Ссылка на запись</td>
|
<td>Ссылка на запись</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
@ -45,6 +50,7 @@
|
|||||||
<!-- <td>{{ entry.Operator }}</td> -->
|
<!-- <td>{{ entry.Operator }}</td> -->
|
||||||
<td>{{ entry.time }}</td>
|
<td>{{ entry.time }}</td>
|
||||||
<td>
|
<td>
|
||||||
|
<<<<<<< HEAD
|
||||||
{% if entry.status == 0 %}
|
{% if entry.status == 0 %}
|
||||||
Вызов принят
|
Вызов принят
|
||||||
{% elif entry.status == 1 %}
|
{% elif entry.status == 1 %}
|
||||||
@ -58,6 +64,8 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
|
=======
|
||||||
|
>>>>>>> parent of c52dc73 (Добавил поиск)
|
||||||
{% if entry.recordUrl|length > 1 %}
|
{% if entry.recordUrl|length > 1 %}
|
||||||
<audio src="{{ entry.recordUrl }}" type="audio/mp3" preload="none" controls>Запись</audio>
|
<audio src="{{ entry.recordUrl }}" type="audio/mp3" preload="none" controls>Запись</audio>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
BIN
worker-dev/__pycache__/config.cpython-39.pyc
Normal file
BIN
worker-dev/__pycache__/config.cpython-39.pyc
Normal file
Binary file not shown.
BIN
worker-dev/__pycache__/msg.cpython-39.pyc
Normal file
BIN
worker-dev/__pycache__/msg.cpython-39.pyc
Normal file
Binary file not shown.
44
worker-dev/app.py
Normal file
44
worker-dev/app.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import pika
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
|
import config
|
||||||
|
from pymongo import MongoClient
|
||||||
|
from msg import msg
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
|
||||||
|
def main():
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
||||||
|
"192.168.0.20", 5672, "mkt", pika.PlainCredentials(
|
||||||
|
"rabbit", "mrl2X0jwnYuCCiKFTshG7WKyOAhfDo")
|
||||||
|
))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
def callback(ch, method, properties, body: bytearray):
|
||||||
|
srcJson = json.loads(str(body.decode('utf-8')).replace("\'", "\""))
|
||||||
|
# if srcJson['state'] == 'HANGUP' and srcJson['direction'] == 'incoming' and srcJson['from'] == '89135853246':
|
||||||
|
try:
|
||||||
|
if srcJson['callstatus'] != 'ANSWER':
|
||||||
|
print(srcJson)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
channel.basic_consume(
|
||||||
|
queue='copy_incoming', on_message_callback=callback, auto_ack=False)
|
||||||
|
|
||||||
|
print(' [*] Waiting for messages. To exit press CTRL+C')
|
||||||
|
channel.start_consuming()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Interrupted')
|
||||||
|
try:
|
||||||
|
sys.exit(0)
|
||||||
|
except SystemExit:
|
||||||
|
os._exit(0)
|
16
worker-dev/config.py
Normal file
16
worker-dev/config.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
|
||||||
|
IMPORTANT_LINE = ['83912051045']
|
||||||
|
|
||||||
|
IGNORE_LIST = ['83912051045',
|
||||||
|
'83912051046',
|
||||||
|
'83919865589',
|
||||||
|
'83919865589',
|
||||||
|
'84950213944',
|
||||||
|
'84951183750',
|
||||||
|
'84951252791',
|
||||||
|
'89919237009',
|
||||||
|
'89919241441',
|
||||||
|
'89919398228',
|
||||||
|
'89919500798',
|
||||||
|
'89919505445',
|
||||||
|
'89919863883']
|
14
worker-dev/dockerfile
Normal file
14
worker-dev/dockerfile
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
FROM alpine
|
||||||
|
|
||||||
|
RUN apk update && apk upgrade && apk add python3 && apk add -U tzdata
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
COPY requirements.txt requirements.txt
|
||||||
|
ADD *.py /app
|
||||||
|
RUN python3 -m venv .venv
|
||||||
|
RUN /app/.venv/bin/pip3 install -r /app/requirements.txt
|
||||||
|
|
||||||
|
EXPOSE 5000
|
||||||
|
|
||||||
|
CMD [".venv/bin/python3", "app.py"]
|
94
worker-dev/getmsg.py
Normal file
94
worker-dev/getmsg.py
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
import pika
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
|
import config
|
||||||
|
from pymongo import MongoClient
|
||||||
|
from msg import msg
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
|
||||||
|
CONNECTION_STRING = "mongodb://mongodb:Cc03Wz5XX3iI3uY3@192.168.0.20"
|
||||||
|
db_connection = MongoClient(CONNECTION_STRING)
|
||||||
|
|
||||||
|
db_base = db_connection["phone"]
|
||||||
|
coll_call = db_base["phone_dev"]
|
||||||
|
from_api = db_base["from_api"]
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
connection = pika.BlockingConnection(pika.ConnectionParameters(
|
||||||
|
"192.168.0.20", 5672, "mkt", pika.PlainCredentials(
|
||||||
|
"rabbit", "mrl2X0jwnYuCCiKFTshG7WKyOAhfDo")
|
||||||
|
))
|
||||||
|
channel = connection.channel()
|
||||||
|
|
||||||
|
def callback(ch, method, properties, body: bytearray):
|
||||||
|
m = msg(body)
|
||||||
|
|
||||||
|
# Разбираем входящие звонки
|
||||||
|
if m.isIncoming():
|
||||||
|
# Если статус START
|
||||||
|
if m.getState() == "START":
|
||||||
|
insert_value = {
|
||||||
|
"uuid": m.getUUID(),
|
||||||
|
"status": -1,
|
||||||
|
"canClose": 0
|
||||||
|
}
|
||||||
|
|
||||||
|
coll_call.update_one(
|
||||||
|
filter={"client": m.getClient(), "status": -1},
|
||||||
|
update={"$set": insert_value},
|
||||||
|
upsert=True
|
||||||
|
)
|
||||||
|
#print("НАЧАТ:", m.dict)
|
||||||
|
|
||||||
|
# Если Статус END
|
||||||
|
if m.getState() == "END":
|
||||||
|
coll_call.update_one(
|
||||||
|
filter={"uuid": m.getUUID()},
|
||||||
|
update={"$set": {"canClose": 1}}
|
||||||
|
)
|
||||||
|
#print("ЗАКОНЧЕН:", m.dict)
|
||||||
|
time.sleep(5)
|
||||||
|
resp = requests.get("https://callinfo.services.mobilon.ru/api/call/info/1e86a98e026578eb5f6bf8c092c0c4a2/" + m.getUUID())
|
||||||
|
j = json.loads(resp.content.decode('utf-8'))
|
||||||
|
d = dict(j)
|
||||||
|
from_api.insert_one(d)
|
||||||
|
|
||||||
|
# Если статус HANGUP
|
||||||
|
if m.getState() == "HANGUP":
|
||||||
|
if m.isAnswered():
|
||||||
|
insert_value = {
|
||||||
|
"status": 0,
|
||||||
|
"duration": m.getDuration(),
|
||||||
|
"recordUrl": m.getRecordUrl()
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
insert_value = {
|
||||||
|
"status": 1
|
||||||
|
}
|
||||||
|
coll_call.update_one(
|
||||||
|
filter={"uuid": m.getUUID(), "canClose": 1},
|
||||||
|
update={"$set": insert_value}
|
||||||
|
)
|
||||||
|
#print("Положена трубка:", m.dict)
|
||||||
|
|
||||||
|
channel.basic_consume(
|
||||||
|
queue='test', on_message_callback=callback, auto_ack=True)
|
||||||
|
|
||||||
|
print(' [*] Waiting for messages. To exit press CTRL+C')
|
||||||
|
channel.start_consuming()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
try:
|
||||||
|
main()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Interrupted')
|
||||||
|
try:
|
||||||
|
sys.exit(0)
|
||||||
|
except SystemExit:
|
||||||
|
os._exit(0)
|
68
worker-dev/msg.py
Normal file
68
worker-dev/msg.py
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import os
|
||||||
|
import json
|
||||||
|
import datetime
|
||||||
|
import re
|
||||||
|
import config
|
||||||
|
|
||||||
|
|
||||||
|
class msg:
|
||||||
|
def __init__(self, body):
|
||||||
|
self.body: bytearray = body
|
||||||
|
self.decode: str = self.body.decode('utf-8')
|
||||||
|
self.json: json = json.loads(self.decode.replace("\'", "\""))
|
||||||
|
self.dict: dict = dict(self.json)
|
||||||
|
|
||||||
|
def getDirection(self):
|
||||||
|
try:
|
||||||
|
return self.dict["direction"]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def isIncoming(self) -> bool:
|
||||||
|
return True if self.dict["direction"] == "incoming" else False
|
||||||
|
|
||||||
|
def isExternal(self) -> bool:
|
||||||
|
return not self.isIncoming()
|
||||||
|
|
||||||
|
def getState(self) -> str:
|
||||||
|
try:
|
||||||
|
return self.dict["state"]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getClient(self) -> str:
|
||||||
|
return self.dict["from"] if self.isIncoming() else self.dict["to"]
|
||||||
|
|
||||||
|
def getTime(self) -> str:
|
||||||
|
try:
|
||||||
|
return datetime.datetime.fromtimestamp(self.dict["time"]).strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
except:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def getStatus(self) -> int:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def getRecordUrl(self) -> str:
|
||||||
|
return self.dict["recordUrl"]
|
||||||
|
|
||||||
|
def getDuration(self) -> int:
|
||||||
|
return self.dict["duration"]
|
||||||
|
|
||||||
|
def getUUID(self) -> str:
|
||||||
|
try:
|
||||||
|
return self.dict["uuid"]
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
def isAnswered(self) -> bool:
|
||||||
|
try:
|
||||||
|
self.dict["callstatus"]
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def isImportant(self):
|
||||||
|
try:
|
||||||
|
return True if self.getState() == "START" and self.isIncoming() and self.dict["to"] in config.IMPORTANT_LINE else False
|
||||||
|
except:
|
||||||
|
pass
|
8
worker-dev/requirements.txt
Normal file
8
worker-dev/requirements.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
dnspython==2.3.0
|
||||||
|
pika==1.3.1
|
||||||
|
pymongo==4.3.3
|
||||||
|
certifi==2022.12.7
|
||||||
|
charset-normalizer==3.1.0
|
||||||
|
idna==3.4
|
||||||
|
requests==2.28.2
|
||||||
|
urllib3==1.26.15
|
@ -84,20 +84,17 @@ def main():
|
|||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
if srcJson['direction'] == 'external':
|
if srcJson['direction'] == 'external':
|
||||||
print("EXTERNAL", srcJson)
|
# coll_phone.update_one({'$and': [{'client': {'$regex': srcJson['to']}}, {'status': 1}}]}, {'$set': {'status': 2, 'callid': srcJson['uuid']}})
|
||||||
|
coll_phone.update_one({'$and': [{'client': {'$regex': srcJson['to']}}, {'status': 1}]}, {'$set': {'status': 2, 'callid': srcJson['uuid']}})
|
||||||
if srcJson['state'] == 'HANGUP':
|
if srcJson['state'] == 'HANGUP':
|
||||||
print("Full Log", srcJson)
|
|
||||||
try:
|
try:
|
||||||
# Проверяем заполнено ли поле recordURL, если нет то меняем статус на 4
|
# Проверяем заполнено ли поле recordURL, если нет то меняем статус на 4
|
||||||
if len(srcJson['recordUrl']) > 4:
|
if len(srcJson['recordUrl']) > 4:
|
||||||
print("recordURL len > 4")
|
print(srcJson['uuid'], srcJson['recordUrl'])
|
||||||
r = coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'recordUrl': srcJson['recordUrl'], 'status': 2}})
|
coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'recordUrl': srcJson['recordUrl'], 'status': 2}})
|
||||||
print(r)
|
|
||||||
else:
|
else:
|
||||||
coll_prone
|
print(srcJson['uuid'])
|
||||||
print("recordURL len < 4")
|
coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'status': 4}})
|
||||||
r = coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'status': 4}})
|
|
||||||
print(r)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user