api.py 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # update: 2024-3-23
  2. """
  3. 配置hosts
  4. 10.10.4.103 cloudos.service.ob.local
  5. 10.62.115.83 harbor.platform.dyys.com
  6. 10.62.115.11 hyty-ifactory.platform.dyys.com
  7. 10.62.115.83 harbor.platform.dyys.com
  8. 10.62.115.11 qbee.platform.dyys.com
  9. 10.62.115.208 mdm.platform.dyys.com
  10. 10.62.107.11 paas.pre.platform.dyys.com
  11. 10.62.107.11 qbee.pre.platform.dyys.com
  12. 10.62.115.11 dacoo.platform.dyys.com
  13. 10.62.115.11 data-assets-process.platform.dyys.com
  14. 10.62.115.11 bitmagic.platform.dyys.com
  15. """
  16. import requests
  17. import sys
  18. import importlib
  19. import traceback
  20. # sys.path.append(r'E:\casper\repositories\repositories\casperz.py-project\module-py') # for pc
  21. sys.path.append('/home/ubuntu/repositories/repositories/casperz.py-project/module-py')
  22. methods = importlib.import_module(f"xlib")
  23. class API(object):
  24. # def __init__(self, username='System001', password='Swdx@143',
  25. def __init__(self, username='', password=''):
  26. """
  27. """
  28. self.url = f"http://hyty-ifactory.platform.dyys.com/gongyi/ui/ResiduePackage/driver/getParamsSet"
  29. def get_pot_list(self):
  30. """
  31. 获取渣罐数据
  32. return [
  33. {
  34. 'id': '1427897186149990401',
  35. 'localNumber': '434', # 渣位号
  36. 'packageNumber': None, # 渣包号
  37. 'localX': None, # 渣位坐标X
  38. 'localY': None, # 渣位坐标Y
  39. 'localStatus': 0, # 渣位水管开关转态 0 关闭 非0 开启
  40. 'packageStatus': 1, # 渣包状态 1 空位 2 就绪 3 缓冷(空冷) 4 水冷 5 自冷(水冷) 6 待倒 7 故障
  41. 'weight': None, # 渣包重量
  42. 'createBy': 'admin',
  43. 'createTime': '2021-08-18',
  44. 'updateBy': 'admin',
  45. 'updateTime': '2024-03-23'
  46. }
  47. ]
  48. return dict(code=-1, data=[], message=f"something is wrong. [{exception.__class__.__name__}]",
  49. details=f"{methods.trace_log()}")
  50. """
  51. try:
  52. response = requests.get(url=self.url)
  53. print('API:get_pot_list:url:', self.url)
  54. print('API:get_pot_list:status_code:', response.status_code)
  55. result = response.json().get('result')
  56. # --- check ---
  57. if not result:
  58. reason = '接口数据异常'
  59. detail = f"请求地址: {self.url}, 请求方式: GET, 返回结果: {response.text}"
  60. return reason, detail
  61. # --- fill pot_list ---
  62. pot_list = list()
  63. for index in range(len(result)):
  64. pot_list += result[index]
  65. return pot_list
  66. except Exception as exception:
  67. print(f"API.get_pot_list.exception: {exception.__class__.__name__}")
  68. print(f"API.get_pot_list.traceback: {traceback.format_exc()}")
  69. reason = f"{exception.__class__.__name__}"
  70. detail = f"{traceback.format_exc()}"
  71. return reason, detail
  72. if __name__ == '__main__':
  73. # --- init ---
  74. api = API()
  75. # --- test ---
  76. out = api.get_pot_list()
  77. print(len(out))