123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- import json
- import requests
- import config
- import ast
- #Функция обращения к апи и получение токена
- def requestGetToken(url) -> str:
- login = "11111111111"
- password = "Sharix!"
- #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 msg_to_text(jsonstring):
- jsonObj = json.loads(jsonstring)
- u = jsonObj
- return u
- 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(token):
- headers = {'Authorization': f'Token {token}'}
- url = 'http://testopen.sharix-app.org/api/v1/platform/sharix-users/'
- response = requests.get(url, headers=headers)
- return response
-
-
- class Ticket(object):
- def __init__(self, id, name, group):
- self.id = id
- self.name = name
- self.group = group
-
- def __str__(self):
- return "{0}, {1}, {2},\n".format(self.id, self.name, self.group)
-
- def requestGetList(auth_token, url):
- headers = {'Authorization': f'Token {auth_token}'}
- response = requests.get(url, headers=headers)
- #response = requests.get(config.API_URL+"/dbsynce/api/orders/", headers=headers)
- tickettext=response.json()
- startlist = []
- if not tickettext:
- print("Empty array")
- else:
- for i in tickettext:
- print (i, "PROCESSING")
- try:
- ticket = Ticket(**i)
- print(i, "Ticket ", ticket)
- startlist.append(ticket)
- except Exception as ex:
- print(ex)
- print (startlist)
- return startlist
- class Ticket_user(object):
- def __init__(self, id, status, title, ticket_type, created_at, updated_at, due_date, priority, created_by, assigned_to):
- self.id = id
- self.status = status
- self.title = title
- self.ticket_type = ticket_type
- self.created_at = created_at
- self.updated_at = updated_at
- self.due_date = due_date
- self.priority = priority
- self.created_by = created_by
- self.assigned_to = assigned_to
-
- def __str__(self):
- return "{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}\n".format(
- self.id, self.status, self.title, self.ticket_type, self.created_at,
- self.updated_at, self.due_date, self.priority,
- self.created_by, self.assigned_to
- )
- def requestGetTicket_user(auth_token, url):
- headers = {'Authorization': f'Token {auth_token}'}
- response = requests.get(url, headers=headers)
-
- #response = requests.get(config.API_URL+"/dbsynce/api/orders/", headers=headers)
- tickettext=response.json()
- startlist = []
- if not tickettext:
- print("Empty array")
- else:
- for i in tickettext:
- try:
- ticket = Ticket_user(**i)
- startlist.append(ticket)
- except Exception as ex:
- print(ex)
- print (startlist)
- return startlist
- def requestPatchTicketUser(token,url, data):
- headers = {'Authorization': f'Token {token}'}
- response = requests.patch(url, json=data, headers=headers)
- return response
- def change_groups(auth_token, url,group):
- headers = {
- 'Content-Type': 'application/json',
- 'Authorization': f'Token {auth_token}'
- }
- response = requests.get(url, headers=headers)
- user_data = response.json()
- current_groups = user_data.get('groups', [])
- updated_groups = list(set([group]+current_groups))
- data = {'groups': updated_groups}
- print(data)
- response = requests.put(url, json=data, headers=headers)
- print(url)
- print(user_data)
- return response
- def change_status_company(auth_token, url,id_metaservice):
- headers = {
- 'Content-Type': 'application/json',
- 'Authorization': f'Token {auth_token}'
- }
- response = requests.get(url, headers=headers)
- user_data = response.json()
- print(user_data)
- current_metaservice = user_data.get('id_metaservice', [])
- repsonse = requests.put(config.API_URL+f"dbsynce/api/company/{id_metaservice}", json=data, headers=headers)
- return response
|