reykit 1.0.1__py3-none-any.whl → 1.1.0__py3-none-any.whl

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.
reydb/rparameter.py DELETED
@@ -1,243 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2022-12-05 14:10:02
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Database parameter methods.
9
- """
10
-
11
-
12
- from typing import Union, Optional, overload
13
-
14
- from .rconnection import RDatabase, RDBConnection
15
-
16
-
17
- __all__ = (
18
- 'RDBParameter',
19
- 'RDBPStatus',
20
- 'RDBPVariable'
21
- )
22
-
23
-
24
- class RDBParameter(object):
25
- """
26
- Rey's `database parameters` type.
27
- """
28
-
29
-
30
- def __init__(
31
- self,
32
- rdatabase: Union[RDatabase, RDBConnection],
33
- global_: bool
34
- ) -> None:
35
- """
36
- Build `database parameters` attributes.
37
-
38
- Parameters
39
- ----------
40
- rdatabase : RDatabase or RDBConnection instance.
41
- global_ : Whether base global.
42
- """
43
-
44
- # Set parameter.
45
- self.rdatabase = rdatabase
46
- self.global_ = global_
47
-
48
-
49
- def __getitem__(self, key: str) -> Optional[str]:
50
- """
51
- Get item of parameter dictionary.
52
-
53
- Parameters
54
- ----------
55
- key : Parameter key.
56
-
57
- Returns
58
- -------
59
- Parameter value.
60
- """
61
-
62
- # Get.
63
- value = self.get(key)
64
-
65
- return value
66
-
67
-
68
- def __setitem__(self, key: str, value: Union[str, float]) -> None:
69
- """
70
- Set item of parameter dictionary.
71
-
72
- Parameters
73
- ----------
74
- key : Parameter key.
75
- value : Parameter value.
76
- """
77
-
78
- # Set.
79
- params = {key: value}
80
-
81
- # Update.
82
- self.update(params)
83
-
84
-
85
- class RDBPStatus(RDBParameter):
86
- """
87
- Rey's `database parameter status` type.
88
- """
89
-
90
-
91
- @overload
92
- def get(self, key: None = None) -> dict[str, str]: ...
93
-
94
- @overload
95
- def get(self, key: str = None) -> Optional[str]: ...
96
-
97
- def get(self, key: Optional[str] = None) -> Union[dict[str, str], Optional[str]]:
98
- """
99
- Get parameter.
100
-
101
- Parameters
102
- ----------
103
- key : Parameter key.
104
- - `None`: Return dictionary of all parameters.
105
- - `str`: Return value of parameter.
106
-
107
- Returns
108
- -------
109
- Status of database.
110
- """
111
-
112
- # Generate SQL.
113
-
114
- ## Global.
115
- if self.global_:
116
- sql = 'SHOW GLOBAL STATUS'
117
-
118
- ## Not global.
119
- else:
120
- sql = 'SHOW STATUS'
121
-
122
- # Execute SQL.
123
-
124
- ## Dictionary.
125
- if key is None:
126
- status = result.fetch_dict(val_field=1)
127
-
128
- ## Value.
129
- else:
130
- sql += ' LIKE :key'
131
- result = self.rdatabase(sql, key=key)
132
- row = result.first()
133
- if row is None:
134
- status = None
135
- else:
136
- status = row['Value']
137
-
138
- return status
139
-
140
-
141
- def update(self, params: dict[str, Union[str, float]]) -> None:
142
- """
143
- Update parameter.
144
-
145
- Parameters
146
- ----------
147
- params : Update parameter key value pairs.
148
- """
149
-
150
- # Throw exception.
151
- raise AssertionError('database status not update')
152
-
153
-
154
- class RDBPVariable(RDBParameter):
155
- """
156
- Rey's `database parameter variable` type.
157
- """
158
-
159
-
160
- @overload
161
- def get(self, key: None = None) -> dict[str, str]: ...
162
-
163
- @overload
164
- def get(self, key: str = None) -> Optional[str]: ...
165
-
166
- def get(self, key: Optional[str] = None) -> Union[dict[str, str], Optional[str]]:
167
- """
168
- Get parameter.
169
-
170
- Parameters
171
- ----------
172
- key : Parameter key.
173
- - `None`: Return dictionary of all parameters.
174
- - `str`: Return value of parameter.
175
-
176
- Returns
177
- -------
178
- Variables of database.
179
- """
180
-
181
- # Generate SQL.
182
-
183
- ## Global.
184
- if self.global_:
185
- sql = 'SHOW GLOBAL VARIABLES'
186
-
187
- ## Not global.
188
- else:
189
- sql = 'SHOW VARIABLES'
190
-
191
- # Execute SQL.
192
-
193
- ## Dictionary.
194
- if key is None:
195
- variables = result.fetch_dict(val_field=1)
196
-
197
- ## Value.
198
- else:
199
- sql += ' LIKE :key'
200
- result = self.rdatabase(sql, key=key)
201
- row = result.first()
202
- if row is None:
203
- variables = None
204
- else:
205
- variables = row['Value']
206
-
207
- return variables
208
-
209
-
210
-
211
- def update(self, params: dict[str, Union[str, float]]) -> None:
212
- """
213
- Update parameter.
214
-
215
- Parameters
216
- ----------
217
- params : Update parameter key value pairs.
218
- """
219
-
220
- # Generate SQL.
221
- sql_set_list = [
222
- '%s = %s' % (
223
- key,
224
- (
225
- value
226
- if value.__class__ in (int, float)
227
- else "'%s'" % value
228
- )
229
- )
230
- for key, value in params.items()
231
- ]
232
- sql_set = ',\n '.join(sql_set_list)
233
-
234
- # Global.
235
- if self.global_:
236
- sql = f'SET GLOBAL {sql_set}'
237
-
238
- ## Not global.
239
- else:
240
- sql = f'SET {sql_set}'
241
-
242
- # Execute SQL.
243
- self.rdatabase(sql)
@@ -1,64 +0,0 @@
1
- reydb/__init__.py,sha256=OoI005B_eXGcInBJEnV-r3IKXcASAXRtk4MW8EnsAhU,519
2
- reydb/rall.py,sha256=B1-E7TMMLOay28T-nm9rqWUvDQDPjwFNAhL-VzR_QAg,319
3
- reydb/rbuild.py,sha256=4vb0PtSKM-Y9Xhn0tSJSxsifmHdmtjHDv-gFGYjca5c,34832
4
- reydb/rconnection.py,sha256=bYwcynvmdpQkLKuDEaetRZxFthcV_sS1xj46HspjmZk,67168
5
- reydb/rexecute.py,sha256=afg4WqF-qvD5M2Lun-k7FZ6bGXuYKl8SKBey4ScZIrQ,9524
6
- reydb/rfile.py,sha256=CwBXgEORWF9QssIgdH9uQlZ4FG8aeowCejruab90dOs,11531
7
- reydb/rinformation.py,sha256=2kBr-X4yE3nlbf-RMsJkkUsdNjo0YCiEhe0wgcfVyzc,13240
8
- reydb/rparameter.py,sha256=aC-TUlwvUB2VUn7MlYJ_gNj5U600KJuYMKE6blOX1ek,5248
9
- reykit/__init__.py,sha256=Azqw5FaTSwK9tatoY01h3ELt0VVWqQL80d8rVEzAlSg,917
10
- reykit/rall.py,sha256=mOFwHXZ4-BOkJ5Ptbm6lQc2zwNf_VqcqM6AYYnYPfoo,672
11
- reykit/rcomm.py,sha256=_i0hrCB3moZhA3sm2ebg54i9dQ8QjI57ZV2cKm0vxA4,11523
12
- reykit/rdata.py,sha256=qmx9yKrfP2frOQjj-34ze8sa1l4sOQXtemkKyrVtKXs,8495
13
- reykit/remail.py,sha256=-uSU2yHyFbjs6X9M5Sjb4TMjw4cK8_Bnsmsaos3f0Rs,6860
14
- reykit/rexception.py,sha256=sI5EKD5gfsdwApovA4DFnlm_MxmPp7TChNLzGmGvZ9M,8150
15
- reykit/rimage.py,sha256=BmNNyhqezN9f40gaE5_rv6B7-v9mYkUwT8n2tfCDfdw,6331
16
- reykit/rlog.py,sha256=J-fnY5B3Y2oJOuyHvemy6ltkr8he4spS3iQOADIUg00,26525
17
- reykit/rmonkey.py,sha256=s8TdR-_tRRMiR11eCLHCkFAJuAZe7PVIhkR-74Xt8vw,7644
18
- reykit/rmultitask.py,sha256=L4_dlIKGV3DrWlID2MDc1Fl-o0kt23l7oYGp4-WJRYU,22057
19
- reykit/rnumber.py,sha256=MajaVOVa3_H1lm91cu9HLaLXd9ZsvZYFxXvcklC0LWs,3209
20
- reykit/ros.py,sha256=wv1DM2N8MXBwGqBhNUSiDLrvHRK7syibhFwEPGkpxYM,39336
21
- reykit/rrandom.py,sha256=4SICHR_ETKG2Syu50wPAZB8DCEmrQq3GQZl6nf4TZ9k,9161
22
- reykit/rregex.py,sha256=E9BConP7ADYyGVZ5jpxwUmtc_WXFb-I1Zjt6IZSHkIQ,6218
23
- reykit/rschedule.py,sha256=TiIFQ0siL20nlhikWfvRGhOdeRbyHQtN6uxFivA2WoI,5852
24
- reykit/rstdout.py,sha256=yjCTegPqm2FNIpNGVrmz16Jn2bNncYO1axuANVdTmVQ,9710
25
- reykit/rsystem.py,sha256=EbPOKtwtVyXqX4AqKMKPW1cEAixqHAOemaxrlEpT0ZY,29388
26
- reykit/rtable.py,sha256=ghsppMMOGkz3boV_CSxpkel5Lfj-ViBziZrpcCoY5YA,12229
27
- reykit/rtext.py,sha256=xilQxaMMdaVCBk6rxQb1aI8-j52QVUH5EtTZVMQsa8Q,11108
28
- reykit/rtime.py,sha256=2xOGGETwl1Sc3W80a2KiPbI4GsSfIyksTeXgqNOTYVw,17178
29
- reykit/rtype.py,sha256=PbfaHjNQTMiZynlz8HwP2K9SS-t91ThMOYBxQIBf9Ug,1975
30
- reykit/rwrap.py,sha256=4RdTxT2y7ViyeiWx2fJ54k9ZZT6Bmx5QStIiwEHB6rY,15320
31
- reykit/rzip.py,sha256=HTrxyb4e6f38eOPFIXsdbcEwr7FQSqnU2MVmVRBYTbg,3563
32
- reykit/rdll/__init__.py,sha256=vM9V7wSNno-WH9RrxgHTIgCkQm8LmBFoLFO8z7qovNo,306
33
- reykit/rdll/rdll_inject.py,sha256=bETl8tywtN1OiQudbA21u6GwBM_bqVX7jbiisNj_JBg,645
34
- reykit/rdll/rdll_inject_core.py,sha256=Trgh_pdJs_Lw-Y-0Kkn8kHr4BnilM9dBKnHnX25T_pM,5092
35
- reyweb/__init__.py,sha256=DKX_nTvcEY1UX7SCRdCgid-ak1XkLruvNzl50T5tl6o,287
36
- reyweb/rall.py,sha256=jHEW2PQkHddvxeaTUukPGb2p-3tXROPP4Cfdp4L_RWc,188
37
- reyweb/rbaidu/__init__.py,sha256=8HLCTEhMwGudKmGAHJ3Ix-pE4HY8ul6UEAisTPzoGO4,426
38
- reyweb/rbaidu/rbaidu_base.py,sha256=RjNaw713l2Fah2Xr9_SLXgAbWE0NAmucc-6rdSPG8tw,4134
39
- reyweb/rbaidu/rbaidu_chat.py,sha256=sYZ_w0arZ-SL5ZAYFGjdEoT7fmNwgm9vOQ76H4SOWkQ,8279
40
- reyweb/rbaidu/rbaidu_image.py,sha256=D4-VjaaZxvljhmv8qfaZ2N1qFY-Evkkw4S08m_l6jws,3997
41
- reyweb/rbaidu/rbaidu_voice.py,sha256=s6bf5K2fTlsBdINN-BGimAoCMGBdet-OSRiTLGbTkWY,5609
42
- reywechat/__init__.py,sha256=3dIerRyo2kL6MDzHaxcDb-FgPswFq6wpm8LKR8YYZgc,572
43
- reywechat/rall.py,sha256=2mjjPSzmiyR6AYOpuzP1Fnw75HXTYoRYSoRpCEcYQOc,385
44
- reywechat/rclient.py,sha256=jPoSezFgr4_N64XFcyXP4hqavCrb7UMoqVsQC6hPDAU,21934
45
- reywechat/rdatabase.py,sha256=McG-3GsOzO4jhPPI-_dwf7nIekAJa0M3e1mx2QzGfQo,37327
46
- reywechat/rexception.py,sha256=Q0r64erO4MbtIMHFkIfmTlWYY1A1XqS-brfHEw3Uh_E,1351
47
- reywechat/rexecute.py,sha256=mMyhjoSyG3_hU-j9BVvXdqEzmyXMb-pBqOuZ8MpREOA,4658
48
- reywechat/rlog.py,sha256=N55o-gmLbZ_6NRd8zznLR84Xrmc41h3RODPoqjGjWfQ,4667
49
- reywechat/rreceive.py,sha256=ATZ65656AJWZm43iuu0_xHa7d4KClmVkDSIav_D7Q1Q,31067
50
- reywechat/rschedule.py,sha256=XRCa1QVW0bq8Bhb4mYv-S_aq6-wvQFF3uZ0t2WFTFQI,3474
51
- reywechat/rsend.py,sha256=PIUY3ebAEY-xaTf2k50puWI-jlz5U9kTIjRvbrRpzUE,16221
52
- reywechat/rwechat.py,sha256=pRZPWu1nGfsQoYCC1A-79-xiflEFFzaqwh6Kshv3fdQ,5721
53
- reywechat/data/client_api.dll,sha256=H9uj-x9Ztg0jFZK0yY6NsnyH5_119dQRFfoVVMidxRs,592384
54
- reyworm/__init__.py,sha256=pUER-wZkP_r70mvgcTy2M2n55Zcybzf-iDWSIecOGZo,428
55
- reyworm/rall.py,sha256=gXixof3iLlJxmjS7Nmnk4lAXrHXX5mbYA9r4g7ZCYHU,291
56
- reyworm/rbrowser.py,sha256=QC1E29yNm0wyugKZlBhfkpIIieEus9SrS11Vt-ZMGCk,2612
57
- reyworm/rcalendar.py,sha256=pVifh3HqyaB6vujrS4z2G8QrFM5MYqpE3jq0HdAlLNw,3884
58
- reyworm/rnews.py,sha256=e63m0Lrmy2edvhKic94X3xRRgOySf3oniKu9N6Zyg60,3079
59
- reyworm/rsecurity.py,sha256=IiYTdCCs3VVKkT6Dh8adlZqRvdreJthdcf_R_1zcJqU,6912
60
- reyworm/rtranslate.py,sha256=vsg1EfAtPbff8Zqd5FvArq8Lg5AHOuOJR9aSQoEIVMo,1349
61
- reykit-1.0.1.dist-info/METADATA,sha256=lW4DMDUd0tQQfqKvoXmpLXrsRkPxKS77Nk_HpGArBCM,700
62
- reykit-1.0.1.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
63
- reykit-1.0.1.dist-info/top_level.txt,sha256=2hvySInjpVEcpYg-XFCYVU5xB2TWW8RovoDtBDzAqyE,7
64
- reykit-1.0.1.dist-info/RECORD,,
reyweb/__init__.py DELETED
@@ -1,19 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2023-02-19 18:59:26
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Rey's Web method set.
9
-
10
- Modules
11
- -------
12
- baidu : Baidu API methods.
13
- """
14
-
15
-
16
- from typing import Final
17
-
18
-
19
- __version__: Final[str] = '1.0.0'
reyweb/rall.py DELETED
@@ -1,12 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2024-01-11 22:47:52
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : All methods.
9
- """
10
-
11
-
12
- from .rbaidu import *
reyweb/rbaidu/__init__.py DELETED
@@ -1,21 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2024-01-11 21:55:48
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Baidu API methods.
9
-
10
- Modules
11
- -------
12
- rbaidu_base : Baidu API base methods.
13
- rbaidu_voice : Baidu API voice methods.
14
- rbaidu_Image : Baidu API image methods.
15
- """
16
-
17
-
18
- from .rbaidu_base import *
19
- from .rbaidu_chat import *
20
- from .rbaidu_image import *
21
- from .rbaidu_voice import *
@@ -1,186 +0,0 @@
1
- # !/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
-
4
- """
5
- @Time : 2024-01-11 21:56:56
6
- @Author : Rey
7
- @Contact : reyxbo@163.com
8
- @Explain : Baidu API base methods.
9
- """
10
-
11
-
12
- from typing import Any, TypedDict
13
- from datetime import datetime
14
- from requests import Response
15
- from uuid import uuid1
16
- from reykit.rcomm import request as reytool_request
17
- from reykit.rtime import now
18
-
19
-
20
- __all__ = (
21
- 'RAPIBaidu',
22
- )
23
-
24
-
25
- CallRecord = TypedDict('CallRecord', {'time': datetime, 'data': Any})
26
-
27
-
28
- class RAPIBaidu(object):
29
- """
30
- Rey's `Baidu API` type.
31
- """
32
-
33
-
34
- def __init__(
35
- self,
36
- key: str,
37
- secret: str,
38
- token_valid_seconds: float = 43200
39
- ) -> None:
40
- """
41
- Build `Baidu API` attributes.
42
-
43
- Parameters
44
- ----------
45
- key : API key.
46
- secret : API secret.
47
- token_valid_seconds : Authorization token vaild seconds.
48
- """
49
-
50
- # Set attribute.
51
- self.key = key
52
- self.secret = secret
53
- self.token_valid_seconds = token_valid_seconds
54
- self.cuid = uuid1()
55
- self.call_records: list[CallRecord] = []
56
- self.start_time = now()
57
-
58
-
59
- def get_token(self) -> str:
60
- """
61
- Get token.
62
-
63
- Returns
64
- -------
65
- Token.
66
- """
67
-
68
- # Get parameter.
69
- url = 'https://aip.baidubce.com/oauth/2.0/token'
70
- params = {
71
- 'grant_type': 'client_credentials',
72
- 'client_id': self.key,
73
- 'client_secret': self.secret
74
- }
75
-
76
- # Request.
77
- response = self.request(
78
- url,
79
- params,
80
- method='post'
81
- )
82
-
83
- # Extract.
84
- response_json = response.json()
85
- token = response_json['access_token']
86
-
87
- return token
88
-
89
-
90
- @property
91
- def token(self) -> str:
92
- """
93
- Get authorization token.
94
- """
95
-
96
- # Get parameter.
97
- if hasattr(self, 'token_time'):
98
- token_time: datetime = getattr(self, 'token_time')
99
- else:
100
- token_time = None
101
- if (
102
- token_time is None
103
- or (now() - token_time).seconds > self.token_valid_seconds
104
- ):
105
- self.token_time = now()
106
- self._token = self.get_token()
107
-
108
- return self._token
109
-
110
-
111
- def request(
112
- self,
113
- *args: Any,
114
- **kwargs: Any
115
- ) -> Response:
116
- """
117
- Request.
118
-
119
- Parameters
120
- ----------
121
- args : Position arguments of function.
122
- kwargs : Keyword arguments of function.
123
-
124
- Returns
125
- -------
126
- `Response` instance.
127
- """
128
-
129
- # Request.
130
- response = reytool_request(*args, **kwargs)
131
-
132
- # Check.
133
- content_type = response.headers['Content-Type']
134
- if content_type.startswith('application/json'):
135
- response_json: dict = response.json()
136
- if 'error_code' in response_json:
137
- raise AssertionError('Baidu API request failed', response_json)
138
-
139
- return response
140
-
141
-
142
- def record_call(
143
- self,
144
- **data: Any
145
- ) -> None:
146
- """
147
- Record call.
148
-
149
- Parameters
150
- ----------
151
- data : Record data.
152
- """
153
-
154
- # Get parameter.
155
- record = {
156
- 'time': now(),
157
- 'data': data
158
- }
159
-
160
- # Record.
161
- self.call_records.append(record)
162
-
163
-
164
- @property
165
- def interval(self) -> float:
166
- """
167
- Return the interval seconds from last call.
168
- When no record, then return the interval seconds from start.
169
-
170
- Returns
171
- -------
172
- Interval seconds.
173
- """
174
-
175
- # Get parameter.
176
- if self.call_records == []:
177
- last_time = self.start_time
178
- else:
179
- last_time: datetime = self.call_records[-1]['time']
180
-
181
- # Count.
182
- now_time = now()
183
- interval_time = now_time - last_time
184
- interval_seconds = interval_time.total_seconds()
185
-
186
- return interval_seconds