Эх сурвалжийг харах

json template for open added

Dev Server 1 жил өмнө
parent
commit
6b433812e5
2 өөрчлөгдсөн 56 нэмэгдсэн , 11 устгасан
  1. 53 9
      jsonAndRequest.py
  2. 3 2
      open_template_bot.py

+ 53 - 9
jsonAndRequest.py

@@ -1,15 +1,49 @@
 import json
 import requests
 #Тестовый класс User и Address (ВАЖНО!!!) поля классов должны называться также как и поля json объекта
-class Address(object):
-    def __init__(self, street, number):
-        self.street = street
-        self.number = number
 
-    def __str__(self):
-        return "{0} {1}".format(self.street, self.number)
 
-class User(object):
+#{
+#    
+#    "ticket": null,
+#    "state": "",
+#    "id_metaservice": null,
+#    "is_global": false,
+#    "is_visible": false,
+#    "service": null,
+#    "service_type": null,
+#
+#    "time_placed": null,
+#    "time_start": null,
+#    "time_start_predicted": null
+#    "time_finish_predicted": null,
+#    "time_start_real":
+#    "time_finish_real": null,
+#    
+#    "order_place_start": "р-н Беговой",
+#    "order_place_start_gps": "р-н Беговой",
+#    "order_place_start_real": "р-н Беговой",
+#    "order_place_start_real_gps": "р-н Беговой",
+#    "order_place_finish_predicted": "р-н Мещанский",
+#    "order_place_finish_predicted_gps": "р-н Мещанский",
+#    "order_place_finish_real": "р-н Мещанский",
+#    "order_place_finish_real_gps": "р-н Мещанский",
+#
+#    "predicted_price": null,
+#    "real_price": null,
+#    "payment_transaction_id"
+#    "rating_id"
+#
+#    "provider": null,
+#    "provider_screen_name": null
+#    "receiver": null,
+#    "receiver_screen_name": nulll
+#    "client_id": null
+#    "resource_id"
+#}
+
+
+class Order(object):
     def __init__(self, name, address):
         self.name = name
         self.address = Address(**address)
@@ -18,10 +52,10 @@ class User(object):
         return "{0} ,{1}".format(self.name, self.address)
 
 #Функция преобразования json в объект класса 
-def jsonToUser(jsonstring) -> User:
+def jsonToClass(jsonstring) -> Order:
     jsonObj = json.loads(jsonstring)
     print(jsonObj)
-    u = User(**jsonObj)
+    u = Order(**jsonObj)
     return u
 
 #Функция обращения к апи и получение токена
@@ -55,3 +89,13 @@ def requestGetListUser():
     response = requests.get(url, headers=headers)
     print(response)
     print(response.json())
+
+
+def requestGetList(token, url):
+    #auth_token=requestGetToken()
+    #print(auth_token)
+    headers = {'Authorization': f'Token {auth_token}'}
+    #url = 'https://user.sharix-app.org/platform/api/sharix-users/'
+    response = requests.get(url, headers=headers)
+    print(response)
+    print(response.json())

+ 3 - 2
open_template_bot.py

@@ -62,7 +62,7 @@ def message_handler(conn, mess):
         print(mess)
 
         if text is not None:
-            orderObj = jsreq.jsonToUser(text)
+            orderObj = jsreq.jsonToClass(text)
             print (orderObj)
             tasklist.append(orderObj)
             process_status.append(0)
@@ -132,7 +132,8 @@ def open_bot_template():
 tasklist = []
 
 #надо инициализировать tasklist при запуске из API
-requestGetToken(botname, PASSWORD, API_URL)
+token = requestGetToken(botname, PASSWORD, API_URL+"/auth/token/login/")
+
 
 
 #список статусов обработки заказов