Browse Source

json parsing for ordinary ticket fixed

Dev Server 1 year ago
parent
commit
2d6dd89ff6
2 changed files with 15 additions and 8 deletions
  1. 12 5
      jsonAndRequest.py
  2. 3 3
      open_template_bot.py

+ 12 - 5
jsonAndRequest.py

@@ -1,6 +1,7 @@
 import json
 import requests
 import config
+import ast
 
 #Тестовый класс User и Address (ВАЖНО!!!) поля классов должны называться также как и поля json объекта
 
@@ -180,7 +181,7 @@ class OrderTicket(object):
         self.assigned_to = assigned_to
 
     def  __str__(self):
-        return "{0}, {1}, {2}, {3}, {4}, {5}, {6},\n{7}, {8}, {9}, {10}, {11}, {12},\n".format(self.id, self.status, self.created_date, self.status_changed_date, self.priority, self.title, self.note, self.due_date, self.task_list, self.created_by, self.type, self.assigned_to) 
+        return "{0}, {1}, {2}, {3}, {4}, {5}, {6},\n{7}, {8}, {9}, {10}, {11}\n".format(self.id, self.status, self.created_date, self.status_changed_date, self.priority, self.title, self.note, self.due_date, self.task_list, self.created_by, self.type, self.assigned_to) 
 
 #Функция преобразования json в объект класса Order
 def jsonToOrder(jsonstring) -> Order:
@@ -191,6 +192,7 @@ def jsonToOrder(jsonstring) -> Order:
 
 #Функция преобразования json в объект класса OrderTicket
 def jsonToOrderTicket(jsonstring) -> OrderTicket:
+    print (jsonstring)
     jsonObj = json.loads(jsonstring)
     print(jsonObj)
     u = OrderTicket(**jsonObj)
@@ -238,7 +240,7 @@ def requestGetList(auth_token, url):
     #response = requests.get(config.API_URL+"/metaservicesynced/api/orders/", headers=headers)
     print(response)
     #return response.json()
-    #print(response.json())
+    print(response.json())
     ordertext=response.json()
     startlist = []
     
@@ -254,11 +256,16 @@ def requestGetList(auth_token, url):
     #            print(ex)
 
     if ordertext is not None:
-            orderObj = jsonToOrderTicket(ordertext)
+        for order in ordertext:
+            print (order)
+            strorder = str(order).replace("'", '"')
+            strorder = strorder.replace("None", 'null')
+            #parsed_json = ast.literal_eval(order)
+            #print (parsed_json)
+            orderObj = jsonToOrderTicket(strorder)
             print (orderObj)
             startlist.append(orderObj)
-            process_status.append(0)
-            bot.bot_log(str(datetime.now())+" аказ успешно добавлен в очередь обработки\n")
+            #bot.bot_log(str(datetime.now())+"Заказ успешно добавлен в очередь обработки\n")
 
 
     #print (orderticket)

+ 3 - 3
open_template_bot.py

@@ -87,9 +87,9 @@ def open_bot_template():
         if (process_status[i]==0):
             print ("Proceeding started", tasklist[i])
             #example of function that should be run each time process is ready
-            bot.fake_api_call(tasklist[i].ticket)
+            bot.fake_api_call(tasklist[i].status)
 
-            if (tasklist[i].ticket==122):
+            if (tasklist[i].status==210):
                 #function that need to be run as thread 
                 #open_bot_template_wait(5,i)
                 t1=threading.Thread(target=open_bot_template_wait, args=(5,i))
@@ -97,7 +97,7 @@ def open_bot_template():
                 process_status[i] +=1
                 continue
 
-            if (tasklist[i].ticket>130):
+            if (tasklist[i].status>210):
                 t2=threading.Thread(target=open_bot_template_wait, args=(15,i))
                 t2.start()
                 print("Заказ оставлен в очереди\n")