123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- import json
- import requests
- #Тестовый класс User и Address (ВАЖНО!!!) поля классов должны называться также как и поля json объекта
- #{
- #
- # "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, ticket, state, id_metaservice, is_global, is_visible, service, service_type, time_placed, time_start, time_start_predicted, time_finish_predicted, time_start_real, time_finish_real, 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, real_price, payment_transaction_id, rating_id, provider, provider_screen_name, receiver, receiver_screen_name, client_id, resource_id):
- self.ticket = ticket
- self.state = state
- self.id_metaservice = id_metaservice
- self.is_global = is_global
- self.is_visible = is_visible
- self.service = service
- self.service_type = service_type
- self.time_placed = time_placed
- self.time_start = time_start
- self.time_start_predicted = time_start_predicted
- self.time_finish_predicted = time_finish_predicted
- self.time_start_real = time_start_real
- self.time_finish_real = time_finish_real
- self.order_place_start = order_place_start
- self.order_place_start_gps = order_place_start_gps
- self.order_place_start_real = order_place_start_real
- self.order_place_start_real_gps = order_place_start_real_gps
- self.order_place_finish_predicted = order_place_finish_predicted
- self.order_place_finish_predicted_gps = order_place_finish_predicted_gps
- self.order_place_finish_real = order_place_finish_real
- self.order_place_finish_real_gps = order_place_finish_real_gps
- self.predicted_price = predicted_price
- self.real_price = real_price
- self.payment_transaction_id = payment_transaction_id
- self.rating_id = rating_id
- self.provider = provider
- self.provider_screen_name = provider_screen_name
- self.receiver = receiver
- self.receiver_screen_name = receiver_screen_name
- self.client_id = client_id
- self.resource_id = resource_id
- #доделать до конца по аналогии с закоммиченным json
- def __str__(self):
- return "{0}, {1}, {2}, {3}, {4}, {5}, {6},\n{7}, {8}, {9}, {10}, {11}, {12},\n{13}, {14}, {15}, {16}, {17}, {18}, {19}, {20},\n{21}, {22}, {23}, {24},\n{25}, {26}, {27}, {28}, {29}, {30}".format(self.ticket, self.state, self.id_metaservice, self.is_global, self.is_visible, self.service, self.service_type, self.time_placed, self.time_start, self.time_start_predicted, self.time_finish_predicted, self.time_start_real, self.time_finish_real, self.order_place_start, self.order_place_start_gps, self.order_place_start_real, self.order_place_start_real_gps, self.order_place_finish_predicted, self.order_place_finish_predicted_gps, self.order_place_finish_real, self.order_place_finish_real_gps, self.predicted_price, self.real_price, self.payment_transaction_id, self.rating_id, self.provider, self.provider_screen_name, self.receiver, self.receiver_screen_name, self.client_id, self.resource_id)
- #\n добавляете в местах с пустой строкой в шаблоне
-
- #Функция преобразования json в объект класса
- def jsonToClass(jsonstring) -> Order:
- jsonObj = json.loads(jsonstring)
- print(jsonObj)
- u = Order(**jsonObj)
- return u
- #Функция обращения к апи и получение токена
- def requestGetToken(login, password, url) -> str:
- #login = "79876543210"
- #password = "admin12345@"
- #url = "https://user.sharix-app.org/auth/token/login/"
- data = {
- "password": password,
- "phone_number": login
- }
- response = requests.post(url, json=data)
- result = response.json()
- return result['auth_token']
- #Функция обращения к апи и получение токена
- def createUser(username, phone, password, url) -> str:
- data = {
- "username": username,
- "phone_number": phone,
- "password": password
- }
- response = requests.post(url, json=data)
- result = response.json()
- return result
- #Функция обращения к апи и получение списка пользователей
- def requestGetListUser():
- 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())
- 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())
|