123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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, name, address):
- self.name = name
- self.address = Address(**address)
-
- def __str__(self):
- return "{0} ,{1}".format(self.name, self.address)
- #Функция преобразования 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())
|