DEV
This commit is contained in:
parent
285e2913f1
commit
73d4ae393e
17
web/app.py
17
web/app.py
@ -16,7 +16,7 @@ app = Flask(__name__)
|
||||
internal = {}
|
||||
external = {}
|
||||
State = ""
|
||||
|
||||
findLimit = 200
|
||||
|
||||
@app.route("/")
|
||||
def root():
|
||||
@ -29,13 +29,14 @@ IgnoreList = ['83919865589', '83912051046', '83912051045', '84950213944', '84951
|
||||
|
||||
@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}}).sort('time', -1)
|
||||
call = coll_call.find({'client': {'$nin': IgnoreList}}).limit(findLimit).sort('time', -1)
|
||||
return render_template("TestCall.html", call=call)
|
||||
|
||||
|
||||
@ -50,10 +51,20 @@ def GetTestId(id):
|
||||
def WebCallStatus(id):
|
||||
call = coll_call.find({"status": int(id)}).sort('time', -1)
|
||||
call = coll_call.find(
|
||||
{'client': {'$nin': IgnoreList}, 'status': int(id)}).sort('time', -1)
|
||||
{'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)
|
||||
|
@ -11,25 +11,21 @@
|
||||
<header>
|
||||
<a href="/web/call/status/0">Входящий вызов принят</a>
|
||||
<a href="/web/call/status/1">Входящий вызов не принят</a>
|
||||
<<<<<<< HEAD
|
||||
<a href="/web/call/status/2">Перезвонили успешно</a>
|
||||
<a href="/web/call/status/4">Перезвонили безуспешно</a>
|
||||
<p>
|
||||
|
||||
</header>
|
||||
|
||||
<form name="search" action="/web/call/find/" method="get" class="search">
|
||||
<label class="search_label">Поиск</label>
|
||||
<input class="search_text" type="text" name="client">
|
||||
<input class="search_btn" type="submit" title="Найти">
|
||||
</form>
|
||||
</p>
|
||||
=======
|
||||
<a href="/web/call/status/2">Перезвонили</a>
|
||||
|
||||
>>>>>>> parent of c52dc73 (Добавил поиск)
|
||||
</header>
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td>Номер клиента</td>
|
||||
<!-- <td>Номер оператора</td> -->
|
||||
<td>Дата время</td>
|
||||
<td>Ссылка на запись</td>
|
||||
</tr>
|
||||
@ -50,7 +46,6 @@
|
||||
<!-- <td>{{ entry.Operator }}</td> -->
|
||||
<td>{{ entry.time }}</td>
|
||||
<td>
|
||||
<<<<<<< HEAD
|
||||
{% if entry.status == 0 %}
|
||||
Вызов принят
|
||||
{% elif entry.status == 1 %}
|
||||
@ -64,8 +59,6 @@
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
=======
|
||||
>>>>>>> parent of c52dc73 (Добавил поиск)
|
||||
{% if entry.recordUrl|length > 1 %}
|
||||
<audio src="{{ entry.recordUrl }}" type="audio/mp3" preload="none" controls>Запись</audio>
|
||||
{% endif %}
|
||||
|
@ -7,17 +7,34 @@ import requests
|
||||
from pymongo import MongoClient
|
||||
|
||||
|
||||
|
||||
db_connection = MongoClient("mongodb://mongodb:Cc03Wz5XX3iI3uY3@mongo")
|
||||
db_base = db_connection["phone-dev"]
|
||||
coll_phone = db_base["phone"]
|
||||
coll_source = db_base["source"]
|
||||
phoneAnswer = db_base["phone-answer"]
|
||||
phoneNAnswer = db_base["phone-n-answer"]
|
||||
phoneRecallTrue = db_base["phone-recall-true"]
|
||||
phoneRecallFalse = db_base["phone-recall-false"]
|
||||
phoneLog = db_base["phone-log"]
|
||||
coll_userkey = db_base['userkey']
|
||||
|
||||
coll_phone.insert_one({"test": "Jopa"})
|
||||
coll_userkey.insert_one({"test": "Jopa 2"})
|
||||
mkt_phones = ['83912051046', '83912051045']
|
||||
IgnoreList = ['83919865589', '83912051046', '83912051045', '84950213944', '84951252791', '83919865589',
|
||||
'84951183750', '89919237009', '89919241441', '89919863883', '89919505445', '89919398228', '89919500798']
|
||||
|
||||
|
||||
# Stats:
|
||||
# 0 - ответили
|
||||
# 1 - не приняли
|
||||
# 2 - перезвонили успешно
|
||||
# 4 - Перезвонили неуспешно
|
||||
|
||||
def WriteLog(desc, data, ex = None):
|
||||
try:
|
||||
log = {"dt": datetime.datetime.now(),"desc": desc, "data": data, "ex":ex }
|
||||
phoneLog.insert_one(log)
|
||||
except Exception as e:
|
||||
print("!!!", e)
|
||||
|
||||
def main():
|
||||
|
||||
@ -26,8 +43,6 @@ def main():
|
||||
channel = connection.channel()
|
||||
|
||||
channel.queue_declare(queue='incoming-dev')
|
||||
tmpIncoming = {}
|
||||
# tmpExternal = {}
|
||||
|
||||
def callback(ch, method, properties, body: bytearray):
|
||||
try:
|
||||
@ -37,73 +52,112 @@ def main():
|
||||
srcJson["time"]).strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
# Определяем направление соединения
|
||||
if srcJson['direction'] == 'incoming':
|
||||
# Определяем начальный статус
|
||||
if srcJson['state'] == 'START':
|
||||
# Создаем переменную. Ответ = false, можно закрывать = false, Приоритетная линия
|
||||
if srcJson['to'] == '83912051045':
|
||||
tmpIncoming[srcJson['uuid']] = [False, False, True]
|
||||
else:
|
||||
tmpIncoming[srcJson['uuid']] = [False, False, False]
|
||||
# Обновление статуса при входящем звонке
|
||||
coll_phone.delete_one({'$and': [{'client': srcJson['from']}, {'status': 1}]})
|
||||
if srcJson['state'] == 'ANSWER' and srcJson['uuid'] in tmpIncoming:
|
||||
tmpIncoming[srcJson['uuid']][0] = True
|
||||
if srcJson['state'] == 'END' and srcJson['uuid'] in tmpIncoming:
|
||||
tmpIncoming[srcJson['uuid']][1] = True
|
||||
if srcJson['state'] == 'HANGUP' and srcJson['uuid'] in tmpIncoming and tmpIncoming[srcJson['uuid']][1] == True:
|
||||
try:
|
||||
srcJson['callstatus']
|
||||
insDict = {"client": srcJson['from'], "time": srcJson['time'], "status": 0,
|
||||
"recordUrl": srcJson["recordUrl"], "duration": srcJson["duration"], "important": tmpIncoming[srcJson['uuid']][2]}
|
||||
except Exception as e:
|
||||
print(e)
|
||||
insDict = {
|
||||
"client": srcJson['from'], "time": srcJson['time'], "status": 1, "important": tmpIncoming[srcJson['uuid']][2], "uuid": srcJson['uuid']}
|
||||
finally:
|
||||
coll_phone.insert_one(insDict)
|
||||
tmpIncoming.pop(srcJson['uuid'])
|
||||
try:
|
||||
insUserKey = {'userkey': srcJson['userkey']}
|
||||
coll_userkey.update_one(
|
||||
filter={
|
||||
'operator': srcJson['to'],
|
||||
},
|
||||
update={
|
||||
'$set': insUserKey,
|
||||
},
|
||||
upsert=True
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
# Отсекаем лишние события по признаку длиины номера
|
||||
|
||||
if srcJson['direction'] == 'external':
|
||||
# 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['to'] in mkt_phones and srcJson['direction'] == "incoming" and srcJson['state'] == "HANGUP" and srcJson not in IgnoreList:
|
||||
if srcJson.get("recordUrl", False):
|
||||
# Запись бывает только у принятых вызовов, поэтому сразу добавляем в базу
|
||||
try:
|
||||
# Проверяем заполнено ли поле recordURL, если нет то меняем статус на 4
|
||||
if len(srcJson['recordUrl']) > 4:
|
||||
print(srcJson['uuid'], srcJson['recordUrl'])
|
||||
coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'recordUrl': srcJson['recordUrl'], 'status': 2}})
|
||||
WriteLog("Add Phone Answer", srcJson)
|
||||
phoneAnswer.insert_one(srcJson)
|
||||
except Exception as e:
|
||||
WriteLog("Add Phone Answer", srcJson, e)
|
||||
else:
|
||||
print(srcJson['uuid'])
|
||||
coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'status': 4}})
|
||||
# Добавляем запись только в том случае если ранее номер отсутствовал,
|
||||
# В противном случае обновляем запись
|
||||
try:
|
||||
WriteLog("Add Phone Non Answer", srcJson)
|
||||
phoneNAnswer.update_one(filter={'from': srcJson['from']}, update={'$set': srcJson}, upsert=True)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
WriteLog("Add Phone Non Answer", srcJson, e)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
if srcJson['state'] == "HANGUP" and srcJson['direction'] == "external":
|
||||
if phoneNAnswer.count_documents({"from": srcJson["to"]}) > 0:
|
||||
phoneNAnswer.delete_one(filter = {"from": srcJson["to"]})
|
||||
if srcJson.get("recordUrl", False):
|
||||
phoneRecallTrue.insert_one(srcJson)
|
||||
phoneRecallFalse.delete_one(filter = {"to": srcJson["to"]})
|
||||
else:
|
||||
phoneRecallFalse.insert_one(srcJson)
|
||||
except:
|
||||
print(e.with_traceback)
|
||||
print(e)
|
||||
exit()
|
||||
|
||||
channel.basic_consume(
|
||||
queue='incoming-dev', on_message_callback=callback, auto_ack=False)
|
||||
queue='incoming-dev', on_message_callback=callback, auto_ack=True)
|
||||
|
||||
print(' [*] Waiting for messages. To exit press CTRL+C')
|
||||
channel.start_consuming()
|
||||
|
||||
|
||||
# # Определяем направление соединения
|
||||
# if srcJson['direction'] == 'incoming':
|
||||
# # Определяем начальный статус
|
||||
# if srcJson['state'] == 'START':
|
||||
# # Создаем переменную. Ответ = false, можно закрывать = false, Приоритетная линия
|
||||
# if srcJson['to'] == '83912051045':
|
||||
# tmpIncoming[srcJson['uuid']] = [False, False, True]
|
||||
# else:
|
||||
# tmpIncoming[srcJson['uuid']] = [False, False, False]
|
||||
# # Обновление статуса при входящем звонке
|
||||
# coll_phone.delete_one({'$and': [{'client': srcJson['from']}, {'status': 1}]})
|
||||
# if srcJson['state'] == 'ANSWER' and srcJson['uuid'] in tmpIncoming:
|
||||
# tmpIncoming[srcJson['uuid']][0] = True
|
||||
# if srcJson['state'] == 'END' and srcJson['uuid'] in tmpIncoming:
|
||||
# tmpIncoming[srcJson['uuid']][1] = True
|
||||
# if srcJson['state'] == 'HANGUP' and srcJson['uuid'] in tmpIncoming and tmpIncoming[srcJson['uuid']][1] == True:
|
||||
# try:
|
||||
# srcJson['callstatus']
|
||||
# insDict = {"client": srcJson['from'], "time": srcJson['time'], "status": 0,
|
||||
# "recordUrl": srcJson["recordUrl"], "duration": srcJson["duration"], "important": tmpIncoming[srcJson['uuid']][2]}
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
# insDict = {
|
||||
# "client": srcJson['from'], "time": srcJson['time'], "status": 1, "important": tmpIncoming[srcJson['uuid']][2], "uuid": srcJson['uuid']}
|
||||
# finally:
|
||||
# coll_phone.insert_one(insDict)
|
||||
# tmpIncoming.pop(srcJson['uuid'])
|
||||
# try:
|
||||
# insUserKey = {'userkey': srcJson['userkey']}
|
||||
# coll_userkey.update_one(
|
||||
# filter={
|
||||
# 'operator': srcJson['to'],
|
||||
# },
|
||||
# update={
|
||||
# '$set': insUserKey,
|
||||
# },
|
||||
# upsert=True
|
||||
# )
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
|
||||
# if srcJson['direction'] == 'external':
|
||||
# # 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':
|
||||
# try:
|
||||
# # Проверяем заполнено ли поле recordURL, если нет то меняем статус на 4
|
||||
# if len(srcJson['recordUrl']) > 4:
|
||||
# print(srcJson['uuid'], srcJson['recordUrl'])
|
||||
# coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'recordUrl': srcJson['recordUrl'], 'status': 2}})
|
||||
# else:
|
||||
# print(srcJson['uuid'])
|
||||
# coll_phone.update_one({'callid':srcJson['uuid']}, {'$set': {'status': 4}})
|
||||
# except Exception as e:
|
||||
# print(e)
|
||||
|
||||
# except Exception as e:
|
||||
# print(e.with_traceback)
|
||||
# print(e)
|
||||
# exit()
|
||||
|
||||
# channel.basic_consume(
|
||||
# queue='incoming-dev', on_message_callback=callback, auto_ack=False)
|
||||
|
||||
# print(' [*] Waiting for messages. To exit press CTRL+C')
|
||||
# channel.start_consuming()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
main()
|
||||
|
@ -5,10 +5,9 @@ RUN apk update && apk upgrade && apk add python3 && apk add -U tzdata
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt requirements.txt
|
||||
ADD app.py /app
|
||||
RUN python3 -m venv .venv
|
||||
RUN /app/.venv/bin/pip3 install -r /app/requirements.txt
|
||||
|
||||
ADD app.py /app
|
||||
EXPOSE 5000
|
||||
|
||||
CMD [".venv/bin/python3", "app.py"]
|
Loading…
x
Reference in New Issue
Block a user