ep-sdk-4pd 1.0.1__tar.gz → 1.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ep_sdk_4pd
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: 4paradigm Electricity Platform Service SDK Library for Python
5
5
  Home-page: https://gitlab.4pd.io/electricityproject/electricity-platform-sdk
6
6
  Author: 4paradigm Electricity Platform SDK
@@ -0,0 +1 @@
1
+ __version__ = '1.0.3'
@@ -8,20 +8,23 @@ from ep_sdk_4pd.ep_system import EpSystem
8
8
  from ep_sdk_4pd.models import HistoryDataRequest, PredictDataRequest
9
9
 
10
10
  # test 地址
11
- # endpoint = 'http://172.27.88.56:6001'
12
-
11
+ endpoint = 'http://172.27.88.56:6001'
13
12
 
14
13
  # prod 地址
15
- endpoint = 'http://172.27.88.56:6601'
14
+ # endpoint = 'http://172.27.88.56:6601'
15
+
16
+ # 外网 地址
17
+ # endpoint = 'http://82.157.231.254:6001'
16
18
 
17
19
  Authorization = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlbGVjdHJpY2l0eS1wbGF0Zm9ybSIsInN1YiI6IjEyMyIsImlhdCI6MTc0NjYwNjQ4NSwianRpIjoiMTIzXzE3NDY1Nzc2ODUxNDYiLCJ0eXBlIjoiYWNjZXNzIn0.Clrz_8j3aJlXTWPX-4DS0NxXN9idTcUIc0AtXOMIjd8'
18
20
 
21
+
19
22
  class EpData:
20
23
 
21
24
  @staticmethod
22
25
  def get_history_data(
23
- scope = None,
24
- days = 0
26
+ scope=None,
27
+ days=0
25
28
  ):
26
29
  # 最晚时间为系统时间 D-2
27
30
  date_str = EpSystem.get_system_date(is_online=True)
@@ -83,7 +86,7 @@ class EpData:
83
86
 
84
87
  # 测试
85
88
  if is_test:
86
- system_date=test_time
89
+ system_date = test_time
87
90
 
88
91
  request = PredictDataRequest(
89
92
  scope=scope,
@@ -124,4 +127,4 @@ class EpData:
124
127
  data=response.json().get('data', None),
125
128
  message=response.json().get('message', None),
126
129
  )
127
- return ep_sdk_4pd_models.PredictDataResponse(response=base_resp)
130
+ return ep_sdk_4pd_models.PredictDataResponse(response=base_resp)
@@ -1,23 +1,29 @@
1
1
  import json
2
2
  import logging
3
3
  import os
4
-
4
+ import rsa
5
+ import base64
5
6
  import requests
6
7
 
7
8
  from ep_sdk_4pd import models as ep_sdk_4pd_models
8
9
  from datetime import datetime
9
10
 
10
- from ep_sdk_4pd.models import ModelOutputDirRequest, RunStrategyRequest, CallTrainDoneRequest
11
+ from ep_sdk_4pd.models import ModelOutputDirRequest, RunStrategyRequest, CallTrainDoneRequest, RsaKeyRequest
11
12
 
12
13
  # test 地址
13
- # endpoint = 'http://172.27.88.56:6001'
14
-
14
+ endpoint = 'http://172.27.88.56:6001'
15
15
 
16
16
  # prod 地址
17
- endpoint = 'http://172.27.88.56:6601'
17
+ # endpoint = 'http://172.27.88.56:6601'
18
+
19
+ # 外网 地址
20
+ # endpoint = 'http://82.157.231.254:6001'
18
21
 
19
22
  Authorization = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJlbGVjdHJpY2l0eS1wbGF0Zm9ybSIsInN1YiI6IjEyMyIsImlhdCI6MTc0NjYwNjQ4NSwianRpIjoiMTIzXzE3NDY1Nzc2ODUxNDYiLCJ0eXBlIjoiYWNjZXNzIn0.Clrz_8j3aJlXTWPX-4DS0NxXN9idTcUIc0AtXOMIjd8'
20
23
 
24
+ def rsa_decrypt(privkey, ciphertext):
25
+ decrypted = rsa.decrypt(base64.b64decode(ciphertext), privkey)
26
+ return decrypted.decode('utf-8')
21
27
 
22
28
  class EpSystem:
23
29
 
@@ -71,6 +77,16 @@ class EpSystem:
71
77
  if is_online:
72
78
  # 线上环境,随着真实调用运行时间变化
73
79
  system_date = datetime.now().strftime('%Y-%m-%d')
80
+
81
+ target_date = os.environ.get('TARGET_DATE')
82
+ # target_date = 'JgAgrcfaQBI0h5YtLGGCjH92snKB3pUBOQs8yy0/mxMBdur0jNvAz6LzpU+Vq3QXsf36jy79WCrgVFo+0RwfUN338VJ9Qe+HwPfe0eq29De6eLD3nOl8xORj339dtSEdXq4dwc2mTaIxQc+erpv4acgQ7YVSDX6AuprwfW7c7qxthziqCqHxVm/qZwUkMsQ1fgzVLeICdscbCJbCD5GFYSpohaP5hRebutoa5FqyhYURA/4kxus98lJsENhnOZAACFdnCWDklpkKZyyOq0aKMd8Vv9SWX1LAZVTRjQ1GGuUPyOYjvnhUyNeRo3D85ODGBFeEju8rjDEB8LFSvX5d3Q=='
83
+ if target_date is not None:
84
+ rsa_data = EpSystem.get_rsa_key()
85
+ if rsa_data:
86
+ rsa_private_key = rsa_data['rsa_private_key']
87
+ loaded_privkey = rsa.PrivateKey.load_pkcs1(rsa_private_key.encode('utf-8'))
88
+ decrypted_data = rsa_decrypt(loaded_privkey, target_date)
89
+ system_date = decrypted_data
74
90
  else:
75
91
  # 线下环境
76
92
  system_date = "2024-12-31"
@@ -165,3 +181,37 @@ class EpSystem:
165
181
  return True
166
182
  else:
167
183
  return False
184
+
185
+ @staticmethod
186
+ def get_rsa_key():
187
+ request = RsaKeyRequest()
188
+ response = EpSystem.rsa_key(request=request)
189
+
190
+ if response.code == 200:
191
+ return response.data
192
+ else:
193
+ return None
194
+
195
+ @staticmethod
196
+ def rsa_key(
197
+ request: ep_sdk_4pd_models.RsaKeyRequest = None,
198
+ ) -> ep_sdk_4pd_models.RsaKeyResponse:
199
+
200
+ full_url = f'{endpoint}{request.api}'
201
+ headers = {
202
+ 'content-type': request.content_type,
203
+ 'Authorization': Authorization
204
+ }
205
+
206
+ response = requests.request(
207
+ method=request.method,
208
+ url=full_url,
209
+ headers=headers,
210
+ )
211
+
212
+ base_resp = ep_sdk_4pd_models.BaseResponse(
213
+ code=response.json().get('code', None),
214
+ data=response.json().get('data', None),
215
+ message=response.json().get('message', None),
216
+ )
217
+ return ep_sdk_4pd_models.RsaKeyResponse(response=base_resp)
@@ -202,6 +202,34 @@ class CallTrainDoneResponse(BaseResponse):
202
202
  Model for CallTrainDoneResponse
203
203
  """
204
204
 
205
+ def __init__(self, response: BaseResponse = None, **kwargs):
206
+ super().__init__(
207
+ code=response.code if response else None,
208
+ data=response.data if response else None,
209
+ message=response.message if response else None,
210
+ **kwargs,
211
+ )
212
+
213
+ class RsaKeyRequest(BaseRequest):
214
+ """
215
+ Model for RsaKeyRequest
216
+ """
217
+
218
+ def __init__(
219
+ self
220
+ ):
221
+
222
+ super().__init__()
223
+ self.api = f'/ep/api/sdk/get_rsa_key'
224
+ self.method = 'GET'
225
+ self.content_type = 'application/json'
226
+
227
+
228
+ class RsaKeyResponse(BaseResponse):
229
+ """
230
+ Model for RsaKeyResponse
231
+ """
232
+
205
233
  def __init__(self, response: BaseResponse = None, **kwargs):
206
234
  super().__init__(
207
235
  code=response.code if response else None,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ep_sdk_4pd
3
- Version: 1.0.1
3
+ Version: 1.0.3
4
4
  Summary: 4paradigm Electricity Platform Service SDK Library for Python
5
5
  Home-page: https://gitlab.4pd.io/electricityproject/electricity-platform-sdk
6
6
  Author: 4paradigm Electricity Platform SDK
@@ -8,7 +8,7 @@ DESCRIPTION = '4paradigm Electricity Platform Service SDK Library for Python'
8
8
  AUTHOR = '4paradigm Electricity Platform SDK'
9
9
  AUTHOR_EMAIL = ''
10
10
  URL = 'https://gitlab.4pd.io/electricityproject/electricity-platform-sdk'
11
- VERSION = '1.0.1'
11
+ VERSION = '1.0.3'
12
12
  REQUIRES = ['requests']
13
13
 
14
14
  LONG_DESCRIPTION = ''
@@ -4,7 +4,7 @@ from ep_sdk_4pd.ep_data import EpData
4
4
  def test_predict_data():
5
5
  print('-------------test_predict_data-------------')
6
6
 
7
- data = EpData.get_predict_data(scope="plant",is_test=True,test_time='2023-04-02')
7
+ data = EpData.get_predict_data(scope="plant")
8
8
  print(data)
9
9
  print('-------------------------------------')
10
10
 
@@ -1 +0,0 @@
1
- __version__ = '1.0.1'
File without changes
File without changes