123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- import requests
- import xmpp
- from xmpp import cli
- import config
- from BotClass import JabberBot
- import json
- import hashlib
- from datetime import datetime
- import time
- import threading
- import jsonAndRequest as jsreq
- global tasklist
- botname="open_servicerequest_accepted"
- operating_status='221'
- JID=botname+"@"+config.JSERVER
- PORT=config.PORT
- PASSWORD=hashlib.md5((botname+config.PASSWORD).encode('utf-8')).hexdigest()
- print(JID, PASSWORD)
- listen_to=["open_servicerequest_assigned@ej.sharix-app.org"]
- proceed_to=[botname,"open_servicerequest_process@ej.sharix-app.org", "open_servicerequest_declined@ej.sharix-app.org", "open_servicerequest_forcemajeure@ej.sharix-app.org"]
- idle_value=10
- def log_handler():
- while True:
- with open(f'{botname}.txt', 'a') as log_file:
- log_file.write(f"{time.strftime('%Y-%m-%d %H:%M:%S')} - {botname} is still running...\n")
- time.sleep(3600)
- def message_handler(conn, mess):
- text = mess.getBody()
- user = mess.getFrom()
-
- if (str(user).split("/")[0]) in listen_to:
- if text is not None:
- orderObj = jsreq.jsonToOrder(text)
- tasklist.append(orderObj)
- bot.bot_log(str(datetime.now())+" Поступивший заказ успешно добавлен в очередь обработки\n")
- def open_servicerequest_accepted_wait(period,localtask):
- bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ ожидает\n")
- time.sleep(period)
-
-
- localtask.title=localtask.title+"1"
-
- bot.proceed_status(proceed_to[0],localtask)
- bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ подождал и отправлен в очередь\n")
- def open_servicerequest_accepted_process(localtask):
- bot.bot_log(botname + " " + str(datetime.now()) + " " + "Заказ в обработчике\n")
-
-
- localtask.status='231'
- jsreq.change_to_task(localtask,token)
- bot.proceed_status(proceed_to[1],localtask)
- bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ отправлен\n")
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- def send_message():
- pass
- def create_ticket():
- pass
- def open_servicerequest_accepted():
- log_thread = threading.Thread(target=log_handler)
- log_thread.daemon = True
- log_thread.start()
- while (len(tasklist)):
- localtask=tasklist.pop(0)
- bot.bot_log(botname + " " + datetime.now().strftime('%Y-%m-%d') + " "+ "Заказ в очереди на обработке\n")
- print("EACH TASKLIST", tasklist)
- if (localtask.status!=operating_status):
- localtask.status=239
- jsreq.change_to_task(localtask,token)
- bot.proceed_status(proceed_to[-1],localtask)
- bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ не по адресу, перенаправляем на форсмажор\n")
- continue
- elif True:
- t1=threading.Thread(target=open_servicerequest_accepted_process, args=([localtask]))
- t1.start()
-
-
-
-
-
-
-
-
-
-
-
- tasklist = []
- token = jsreq.requestGetToken(botname, PASSWORD, config.API_URL+"my/api/v1/auth/token/login/")
- tasklist_dbsynce=jsreq.requestGetList(token, config.API_URL+"/dbsynce/api/orders/")
- bot = JabberBot(JID, PASSWORD, PORT)
- bot.register_handler('message', message_handler)
- bot.start(open_servicerequest_accepted)
|