123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- 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_strequest_done"
- operating_status=149
- JID=botname+"@"+config.JSERVER
- PORT=config.PORT
- PASSWORD=hashlib.md5((botname+config.PASSWORD).encode('utf-8')).hexdigest()
- print(JID, PASSWORD)
- listen_to=["test@ej.sharix-app.org", "open_template_bot@ej.sharix-app.org"]
- proceed_to=[botname, "open_strequest_closed@ej.sharix-app.org", "open_servicerequest_forcemajeure@ej.sharix-app.org"]
- idle_value=10
- def message_handler(conn, mess):
- text = mess.getBody()
- user = mess.getFrom()
-
- print (str(user).split("/")[0])
- if (str(user).split("/")[0]) in listen_to:
- print(text)
- print(mess)
- if text is not None:
- orderObj = jsreq.jsonToOrderTicket(text)
- print (orderObj)
- tasklist.append(orderObj)
- bot.bot_log(str(datetime.now())+" Поступивший заказ успешно добавлен в очередь обработки\n")
- def open_strequest_done_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_strequest_done_process(localtask):
- bot.bot_log(botname + " " + str(datetime.now()) + " " + "Заказ в обработчике\n")
- order = jsreq.jsonToOrder(localtask)
- idle_value = idle_value - 1
- if idle_value < 1:
- bot.proceed_status(proceed_to[1],localtask)
- else:
- push_notifications(order)
- open_strequest_done_wait(100,localtask)
-
- if True:
- open_strequest_done_process(localtask)
- def push_notifications(order):
-
-
- return True
- def open_strequest_done():
- 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):
- bot.proceed_status(proceed_to[-1],localtask)
- bot.bot_log(botname+" "+str(datetime.now())+" "+"Заказ не по адресу, перенаправляем на форсмажор\n")
- continue
-
-
-
-
-
-
- t1=threading.Thread(target=open_strequest_done_process, args=(localtask))
- t1.start()
-
- bot.proceed_status(proceed_to[0],localtask)
- print("Заказ возвращен в очередь\n")
- print(tasklist)
- tasklist = []
- token = jsreq.requestGetToken(botname, PASSWORD, config.API_URL+"/auth/token/login/")
- tasklist=jsreq.requestGetList(token, config.API_URL+"/tickets/api/tickets/?list_id=10")
- print (len(tasklist))
- bot = JabberBot(JID, PASSWORD, PORT)
- bot.register_handler('message', message_handler)
- bot.start(open_strequest_done)
|