absfuyu 4.2.0__py3-none-any.whl → 5.0.1__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.
Potentially problematic release.
This version of absfuyu might be problematic. Click here for more details.
- absfuyu/__init__.py +4 -4
- absfuyu/__main__.py +13 -1
- absfuyu/cli/__init__.py +2 -2
- absfuyu/cli/color.py +9 -2
- absfuyu/cli/config_group.py +2 -2
- absfuyu/cli/do_group.py +2 -37
- absfuyu/cli/game_group.py +2 -2
- absfuyu/cli/tool_group.py +7 -7
- absfuyu/config/__init__.py +17 -34
- absfuyu/core/__init__.py +49 -0
- absfuyu/core/baseclass.py +299 -0
- absfuyu/core/baseclass2.py +165 -0
- absfuyu/core/decorator.py +67 -0
- absfuyu/core/docstring.py +166 -0
- absfuyu/core/dummy_cli.py +67 -0
- absfuyu/core/dummy_func.py +49 -0
- absfuyu/dxt/__init__.py +42 -0
- absfuyu/dxt/dictext.py +201 -0
- absfuyu/dxt/dxt_support.py +79 -0
- absfuyu/dxt/intext.py +586 -0
- absfuyu/dxt/listext.py +508 -0
- absfuyu/dxt/strext.py +530 -0
- absfuyu/extra/__init__.py +12 -0
- absfuyu/extra/beautiful.py +252 -0
- absfuyu/{extensions → extra}/data_analysis.py +51 -82
- absfuyu/fun/__init__.py +110 -135
- absfuyu/fun/tarot.py +11 -19
- absfuyu/game/__init__.py +8 -2
- absfuyu/game/game_stat.py +8 -2
- absfuyu/game/sudoku.py +9 -3
- absfuyu/game/tictactoe.py +14 -7
- absfuyu/game/wordle.py +16 -10
- absfuyu/general/__init__.py +8 -81
- absfuyu/general/content.py +24 -38
- absfuyu/general/human.py +108 -228
- absfuyu/general/shape.py +1334 -0
- absfuyu/logger.py +10 -15
- absfuyu/pkg_data/__init__.py +137 -100
- absfuyu/pkg_data/deprecated.py +133 -0
- absfuyu/sort.py +6 -130
- absfuyu/tools/__init__.py +2 -2
- absfuyu/tools/checksum.py +33 -22
- absfuyu/tools/converter.py +51 -48
- absfuyu/{general → tools}/generator.py +17 -42
- absfuyu/tools/keygen.py +25 -30
- absfuyu/tools/obfuscator.py +246 -112
- absfuyu/tools/passwordlib.py +100 -30
- absfuyu/tools/shutdownizer.py +68 -47
- absfuyu/tools/web.py +4 -11
- absfuyu/util/__init__.py +17 -17
- absfuyu/util/api.py +10 -15
- absfuyu/util/json_method.py +7 -24
- absfuyu/util/lunar.py +5 -11
- absfuyu/util/path.py +22 -27
- absfuyu/util/performance.py +43 -67
- absfuyu/util/shorten_number.py +65 -14
- absfuyu/util/zipped.py +11 -17
- absfuyu/version.py +59 -42
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/METADATA +41 -14
- absfuyu-5.0.1.dist-info/RECORD +68 -0
- absfuyu/core.py +0 -57
- absfuyu/everything.py +0 -32
- absfuyu/extensions/__init__.py +0 -12
- absfuyu/extensions/beautiful.py +0 -188
- absfuyu/fun/WGS.py +0 -134
- absfuyu/general/data_extension.py +0 -1796
- absfuyu/tools/stats.py +0 -226
- absfuyu/util/pkl.py +0 -67
- absfuyu-4.2.0.dist-info/RECORD +0 -59
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/WHEEL +0 -0
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/entry_points.txt +0 -0
- {absfuyu-4.2.0.dist-info → absfuyu-5.0.1.dist-info}/licenses/LICENSE +0 -0
absfuyu/tools/shutdownizer.py
CHANGED
|
@@ -3,17 +3,17 @@ Absfuyu: Shutdownizer
|
|
|
3
3
|
---------------------
|
|
4
4
|
This shutdowns
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 23/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module level
|
|
11
|
-
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
12
|
__all__ = ["ShutDownizer", "ShutdownEngine"]
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
# Library
|
|
16
|
-
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
17
|
import os
|
|
18
18
|
import subprocess
|
|
19
19
|
import sys
|
|
@@ -22,20 +22,29 @@ from datetime import datetime, time, timedelta
|
|
|
22
22
|
from pathlib import Path
|
|
23
23
|
from typing import Annotated
|
|
24
24
|
|
|
25
|
+
try:
|
|
26
|
+
from typing import override # type: ignore
|
|
27
|
+
except ImportError:
|
|
28
|
+
from absfuyu.core.decorator import dummy_decorator as override
|
|
29
|
+
|
|
30
|
+
from absfuyu.core import BaseClass, versionadded, versionchanged
|
|
25
31
|
from absfuyu.logger import logger
|
|
26
32
|
|
|
27
33
|
# TODO: Schedule shutdown, random time shutdown, test
|
|
28
34
|
|
|
29
35
|
|
|
30
36
|
# Class
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
# ---------------------------------------------------------------------------
|
|
38
|
+
@versionadded("4.2.0")
|
|
39
|
+
class ShutDownizer(BaseClass):
|
|
33
40
|
"""
|
|
34
41
|
ShutDownizer
|
|
35
42
|
|
|
36
43
|
Shutdown tool because why not
|
|
37
44
|
"""
|
|
38
45
|
|
|
46
|
+
__slots__ = ("os", "engine")
|
|
47
|
+
|
|
39
48
|
def __init__(self) -> None:
|
|
40
49
|
self.os: str = sys.platform
|
|
41
50
|
logger.debug(f"Current OS: {self.os}")
|
|
@@ -52,23 +61,20 @@ class ShutDownizer:
|
|
|
52
61
|
def __str__(self) -> str:
|
|
53
62
|
return f"{self.__class__.__name__}({self.os})"
|
|
54
63
|
|
|
55
|
-
def
|
|
56
|
-
return self.__str__()
|
|
57
|
-
|
|
58
|
-
def shutdown(self) -> None:
|
|
64
|
+
def shutdown(self, *args, **kwargs) -> None:
|
|
59
65
|
"""Shutdown"""
|
|
60
|
-
self.engine.shutdown()
|
|
66
|
+
self.engine.shutdown(*args, **kwargs)
|
|
61
67
|
|
|
62
|
-
def restart(self) -> None:
|
|
68
|
+
def restart(self, *args, **kwargs) -> None:
|
|
63
69
|
"""Restart"""
|
|
64
|
-
self.engine.restart()
|
|
70
|
+
self.engine.restart(*args, **kwargs)
|
|
65
71
|
|
|
66
72
|
def cancel(self) -> None:
|
|
67
73
|
"""Cancel"""
|
|
68
74
|
self.engine.cancel()
|
|
69
75
|
|
|
70
76
|
|
|
71
|
-
class ShutdownEngine(ABC):
|
|
77
|
+
class ShutdownEngine(ABC, BaseClass):
|
|
72
78
|
"""
|
|
73
79
|
Abstract shutdown class for different type of OS
|
|
74
80
|
"""
|
|
@@ -76,9 +82,6 @@ class ShutdownEngine(ABC):
|
|
|
76
82
|
def __str__(self) -> str:
|
|
77
83
|
return f"{self.__class__.__name__}()"
|
|
78
84
|
|
|
79
|
-
def __repr__(self) -> str:
|
|
80
|
-
return self.__str__()
|
|
81
|
-
|
|
82
85
|
def _execute_cmd(self, cmd: str | list) -> None:
|
|
83
86
|
"""Execute the cmd"""
|
|
84
87
|
try:
|
|
@@ -86,8 +89,8 @@ class ShutdownEngine(ABC):
|
|
|
86
89
|
subprocess.run(cmd.split())
|
|
87
90
|
elif isinstance(cmd, list):
|
|
88
91
|
subprocess.run(cmd)
|
|
89
|
-
except Exception:
|
|
90
|
-
logger.error(f'"{cmd}" failed to run')
|
|
92
|
+
except (FileNotFoundError, Exception) as e:
|
|
93
|
+
logger.error(f'"{cmd}" failed to run: {e}')
|
|
91
94
|
raise ValueError(f'"{cmd}" failed to run') # noqa
|
|
92
95
|
|
|
93
96
|
def _execute_multiple_cmds(self, cmds: list) -> None:
|
|
@@ -98,21 +101,21 @@ class ShutdownEngine(ABC):
|
|
|
98
101
|
logger.debug(f"Executing: {cmd}")
|
|
99
102
|
self._execute_cmd(cmd)
|
|
100
103
|
break
|
|
101
|
-
except Exception:
|
|
102
|
-
logger.error(f'"{cmd}" failed to run')
|
|
104
|
+
except Exception as e:
|
|
105
|
+
logger.error(f'"{cmd}" failed to run: {e}')
|
|
103
106
|
|
|
104
107
|
@abstractmethod
|
|
105
|
-
def shutdown(self) -> None:
|
|
108
|
+
def shutdown(self, *args, **kwargs) -> None:
|
|
106
109
|
"""Shutdown"""
|
|
107
110
|
pass
|
|
108
111
|
|
|
109
112
|
@abstractmethod
|
|
110
|
-
def restart(self) -> None:
|
|
113
|
+
def restart(self, *args, **kwargs) -> None:
|
|
111
114
|
"""Restart"""
|
|
112
115
|
pass
|
|
113
116
|
|
|
114
117
|
@abstractmethod
|
|
115
|
-
def sleep(self) -> None:
|
|
118
|
+
def sleep(self, *args, **kwargs) -> None:
|
|
116
119
|
"""Sleep"""
|
|
117
120
|
pass
|
|
118
121
|
|
|
@@ -131,24 +134,29 @@ class ShutdownEngine(ABC):
|
|
|
131
134
|
m: Annotated[int, "positive"] = 0,
|
|
132
135
|
aggregate: bool = True,
|
|
133
136
|
) -> int:
|
|
134
|
-
"""
|
|
137
|
+
"""
|
|
138
|
+
Calculate time for scheduled shutdown.
|
|
135
139
|
|
|
136
140
|
Parameters
|
|
137
141
|
----------
|
|
138
142
|
h : int, optional
|
|
139
|
-
Hours to add (24h format), by default 0
|
|
143
|
+
Hours to add (24h format), by default ``0``
|
|
144
|
+
|
|
140
145
|
m : int, optional
|
|
141
|
-
Minutes to add (24h format), by default 0
|
|
146
|
+
Minutes to add (24h format), by default ``0``
|
|
147
|
+
|
|
142
148
|
aggregate : bool, optional
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
149
|
+
This add hours and and minutes to `time.now()`, by default ``True``
|
|
150
|
+
- ``True`` : Add hours and minutes to current time
|
|
151
|
+
- ``False``: Use ``h`` and ``m`` as fixed time point to shutdown
|
|
146
152
|
|
|
147
153
|
Returns
|
|
148
154
|
-------
|
|
149
155
|
int
|
|
150
|
-
Seconds left
|
|
156
|
+
Seconds left until shutdown.
|
|
151
157
|
"""
|
|
158
|
+
h = max(0, h) # Force >= 0
|
|
159
|
+
m = max(0, m)
|
|
152
160
|
now = datetime.now()
|
|
153
161
|
if aggregate:
|
|
154
162
|
delta = timedelta(hours=h, minutes=m)
|
|
@@ -163,18 +171,29 @@ class ShutdownEngine(ABC):
|
|
|
163
171
|
class ShutdownEngineWin(ShutdownEngine):
|
|
164
172
|
"""ShutDownizer - Windows"""
|
|
165
173
|
|
|
166
|
-
|
|
167
|
-
|
|
174
|
+
@override
|
|
175
|
+
@versionchanged("5.0.0", "Scheduled shutdown")
|
|
176
|
+
def shutdown(
|
|
177
|
+
self,
|
|
178
|
+
h: Annotated[int, "positive"] = 0,
|
|
179
|
+
m: Annotated[int, "positive"] = 0,
|
|
180
|
+
aggregate: bool = True,
|
|
181
|
+
) -> None:
|
|
182
|
+
time_until_sd = self._calculate_time(h=h, m=m, aggregate=aggregate)
|
|
183
|
+
cmds = [f"shutdown -f -s -t {time_until_sd}"]
|
|
168
184
|
self._execute_multiple_cmds(cmds)
|
|
169
185
|
|
|
170
|
-
|
|
186
|
+
@override
|
|
187
|
+
def restart(self, *args, **kwargs) -> None:
|
|
171
188
|
cmds = ["shutdown -r"]
|
|
172
189
|
self._execute_multiple_cmds(cmds)
|
|
173
190
|
|
|
174
|
-
|
|
191
|
+
@override
|
|
192
|
+
def sleep(self, *args, **kwargs) -> None:
|
|
175
193
|
cmds = ["rundll32.exe powrprof.dll,SetSuspendState 0,1,0"]
|
|
176
194
|
self._execute_multiple_cmds(cmds)
|
|
177
195
|
|
|
196
|
+
@override
|
|
178
197
|
def abort(self) -> None:
|
|
179
198
|
cmds = ["shutdown -a"]
|
|
180
199
|
self._execute_multiple_cmds(cmds)
|
|
@@ -196,7 +215,8 @@ class ShutdownEngineWin(ShutdownEngine):
|
|
|
196
215
|
class ShutdownEngineMac(ShutdownEngine):
|
|
197
216
|
"""ShutDownizer - MacOS"""
|
|
198
217
|
|
|
199
|
-
|
|
218
|
+
@override
|
|
219
|
+
def shutdown(self, *args, **kwargs) -> None:
|
|
200
220
|
cmds = [
|
|
201
221
|
["osascript", "-e", 'tell application "System Events" to shut down'],
|
|
202
222
|
"pmset sleepnow",
|
|
@@ -205,7 +225,8 @@ class ShutdownEngineMac(ShutdownEngine):
|
|
|
205
225
|
]
|
|
206
226
|
self._execute_multiple_cmds(cmds)
|
|
207
227
|
|
|
208
|
-
|
|
228
|
+
@override
|
|
229
|
+
def restart(self, *args, **kwargs) -> None:
|
|
209
230
|
cmds = [
|
|
210
231
|
["osascript", "-e", 'tell application "System Events" to restart'],
|
|
211
232
|
"shutdown -r now",
|
|
@@ -213,7 +234,8 @@ class ShutdownEngineMac(ShutdownEngine):
|
|
|
213
234
|
]
|
|
214
235
|
self._execute_multiple_cmds(cmds)
|
|
215
236
|
|
|
216
|
-
|
|
237
|
+
@override
|
|
238
|
+
def sleep(self, *args, **kwargs) -> None:
|
|
217
239
|
cmds = [
|
|
218
240
|
["osascript", "-e", 'tell application "System Events" to sleep'],
|
|
219
241
|
"pmset sleepnow",
|
|
@@ -222,6 +244,7 @@ class ShutdownEngineMac(ShutdownEngine):
|
|
|
222
244
|
]
|
|
223
245
|
self._execute_multiple_cmds(cmds)
|
|
224
246
|
|
|
247
|
+
@override
|
|
225
248
|
def abort(self) -> None:
|
|
226
249
|
cmds = [
|
|
227
250
|
["osascript", "-e", 'tell application "System Events" to cancel shutdown'],
|
|
@@ -235,7 +258,8 @@ class ShutdownEngineMac(ShutdownEngine):
|
|
|
235
258
|
class ShutdownEngineLinux(ShutdownEngine):
|
|
236
259
|
"""ShutDownizer - Linux"""
|
|
237
260
|
|
|
238
|
-
|
|
261
|
+
@override
|
|
262
|
+
def shutdown(self, *args, **kwargs) -> None:
|
|
239
263
|
cmds = [
|
|
240
264
|
"gnome-session-quit --power-off",
|
|
241
265
|
"systemctl --user poweroff",
|
|
@@ -243,7 +267,8 @@ class ShutdownEngineLinux(ShutdownEngine):
|
|
|
243
267
|
]
|
|
244
268
|
self._execute_multiple_cmds(cmds)
|
|
245
269
|
|
|
246
|
-
|
|
270
|
+
@override
|
|
271
|
+
def restart(self, *args, **kwargs) -> None:
|
|
247
272
|
cmds = [
|
|
248
273
|
"gnome-session-quit --reboot",
|
|
249
274
|
"systemctl reboot",
|
|
@@ -251,16 +276,12 @@ class ShutdownEngineLinux(ShutdownEngine):
|
|
|
251
276
|
]
|
|
252
277
|
self._execute_multiple_cmds(cmds)
|
|
253
278
|
|
|
254
|
-
|
|
279
|
+
@override
|
|
280
|
+
def sleep(self, *args, **kwargs) -> None:
|
|
255
281
|
cmds = ["systemctl suspend", "sudo shutdown -s now"]
|
|
256
282
|
self._execute_multiple_cmds(cmds)
|
|
257
283
|
|
|
284
|
+
@override
|
|
258
285
|
def abort(self) -> None:
|
|
259
286
|
cmds = ["sudo shutdown -c"]
|
|
260
287
|
self._execute_multiple_cmds(cmds)
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
# Run
|
|
264
|
-
###########################################################################
|
|
265
|
-
if __name__ == "__main__":
|
|
266
|
-
pass
|
absfuyu/tools/web.py
CHANGED
|
@@ -3,12 +3,12 @@ Absfuyu: Web
|
|
|
3
3
|
------------
|
|
4
4
|
Web, ``request``, ``BeautifulSoup`` stuff
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Library
|
|
11
|
-
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
12
|
import requests
|
|
13
13
|
from bs4 import BeautifulSoup
|
|
14
14
|
|
|
@@ -16,7 +16,7 @@ from absfuyu.logger import logger
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
# Function
|
|
19
|
-
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
20
|
def soup_link(link: str) -> BeautifulSoup:
|
|
21
21
|
"""
|
|
22
22
|
``BeautifulSoup`` the link
|
|
@@ -53,10 +53,3 @@ def gen_random_commit_msg() -> str:
|
|
|
53
53
|
out = soup_link("https://whatthecommit.com/").get_text()[34:-20]
|
|
54
54
|
logger.debug(out)
|
|
55
55
|
return out # type: ignore
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
# Run
|
|
59
|
-
###########################################################################
|
|
60
|
-
if __name__ == "__main__":
|
|
61
|
-
logger.setLevel(10)
|
|
62
|
-
gen_random_commit_msg()
|
absfuyu/util/__init__.py
CHANGED
|
@@ -3,20 +3,21 @@ Absufyu: Utilities
|
|
|
3
3
|
------------------
|
|
4
4
|
Some random utilities
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated: 25/
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 25/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Library
|
|
11
|
-
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
12
|
import pkgutil
|
|
13
13
|
from datetime import datetime
|
|
14
14
|
|
|
15
|
-
from absfuyu.
|
|
15
|
+
from absfuyu.core import deprecated, versionadded, versionchanged
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
# Function
|
|
19
|
-
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
|
+
@versionchanged("2.7.1", reason="Use ``pkgutil`` lib")
|
|
20
21
|
def get_installed_package():
|
|
21
22
|
"""
|
|
22
23
|
Return a list of installed packages
|
|
@@ -32,6 +33,7 @@ def get_installed_package():
|
|
|
32
33
|
return sorted(iter_modules)
|
|
33
34
|
|
|
34
35
|
|
|
36
|
+
@deprecated("5.0.0")
|
|
35
37
|
def set_min(
|
|
36
38
|
current_value: int | float,
|
|
37
39
|
*,
|
|
@@ -60,11 +62,13 @@ def set_min(
|
|
|
60
62
|
>>> set_min(-1)
|
|
61
63
|
0
|
|
62
64
|
"""
|
|
63
|
-
if current_value < min_value:
|
|
64
|
-
|
|
65
|
-
return current_value
|
|
65
|
+
# if current_value < min_value:
|
|
66
|
+
# current_value = min_value
|
|
67
|
+
# return current_value
|
|
68
|
+
return max(min_value, current_value)
|
|
66
69
|
|
|
67
70
|
|
|
71
|
+
@deprecated("5.0.0")
|
|
68
72
|
def set_max(
|
|
69
73
|
current_value: int | float,
|
|
70
74
|
*,
|
|
@@ -93,9 +97,10 @@ def set_max(
|
|
|
93
97
|
>>> set_max(101)
|
|
94
98
|
100
|
|
95
99
|
"""
|
|
96
|
-
if current_value > max_value:
|
|
97
|
-
|
|
98
|
-
return current_value
|
|
100
|
+
# if current_value > max_value:
|
|
101
|
+
# current_value = max_value
|
|
102
|
+
# return current_value
|
|
103
|
+
return min(max_value, current_value)
|
|
99
104
|
|
|
100
105
|
|
|
101
106
|
def set_min_max(
|
|
@@ -137,6 +142,7 @@ def set_min_max(
|
|
|
137
142
|
return current_value
|
|
138
143
|
|
|
139
144
|
|
|
145
|
+
@versionadded("3.2.0")
|
|
140
146
|
def stop_after_day(
|
|
141
147
|
year: int | None = None, month: int | None = None, day: int | None = None
|
|
142
148
|
) -> None:
|
|
@@ -172,9 +178,3 @@ def stop_after_day(
|
|
|
172
178
|
result = end_date - now
|
|
173
179
|
if result.days < 0:
|
|
174
180
|
raise SystemExit("End of time")
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
# Run
|
|
178
|
-
###########################################################################
|
|
179
|
-
if __name__ == "__main__":
|
|
180
|
-
logger.setLevel(10)
|
absfuyu/util/api.py
CHANGED
|
@@ -3,12 +3,12 @@ Absufyu: API
|
|
|
3
3
|
------------
|
|
4
4
|
Fetch data stuff
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module level
|
|
11
|
-
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
12
|
__all__ = [
|
|
13
13
|
"APIRequest",
|
|
14
14
|
"ping_windows",
|
|
@@ -16,7 +16,7 @@ __all__ = [
|
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
# Library
|
|
19
|
-
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
20
|
import json
|
|
21
21
|
import re
|
|
22
22
|
import subprocess
|
|
@@ -24,13 +24,13 @@ from pathlib import Path
|
|
|
24
24
|
from typing import NamedTuple
|
|
25
25
|
|
|
26
26
|
import requests
|
|
27
|
-
from deprecated.sphinx import versionchanged
|
|
28
27
|
|
|
28
|
+
from absfuyu.core import versionadded, versionchanged
|
|
29
29
|
from absfuyu.logger import logger
|
|
30
30
|
|
|
31
31
|
|
|
32
32
|
# Function
|
|
33
|
-
|
|
33
|
+
# ---------------------------------------------------------------------------
|
|
34
34
|
class PingResult(NamedTuple):
|
|
35
35
|
"""
|
|
36
36
|
:param host: Host name/IP
|
|
@@ -41,7 +41,8 @@ class PingResult(NamedTuple):
|
|
|
41
41
|
result: str
|
|
42
42
|
|
|
43
43
|
|
|
44
|
-
@versionchanged(
|
|
44
|
+
@versionchanged("3.4.0", reason="Updated functionality")
|
|
45
|
+
@versionadded("2.5.0")
|
|
45
46
|
def ping_windows(host: list[str], ping_count: int = 3) -> list[PingResult]:
|
|
46
47
|
"""
|
|
47
48
|
Ping web
|
|
@@ -88,7 +89,7 @@ def ping_windows(host: list[str], ping_count: int = 3) -> list[PingResult]:
|
|
|
88
89
|
|
|
89
90
|
|
|
90
91
|
# Class
|
|
91
|
-
|
|
92
|
+
# ---------------------------------------------------------------------------
|
|
92
93
|
class APIRequest:
|
|
93
94
|
"""API data with cache feature"""
|
|
94
95
|
|
|
@@ -143,7 +144,7 @@ class APIRequest:
|
|
|
143
144
|
logger.debug(f"No local cache found... ({e})")
|
|
144
145
|
json_data = None
|
|
145
146
|
|
|
146
|
-
if
|
|
147
|
+
if json_data is None:
|
|
147
148
|
logger.debug("Fetching new json data... (Creating local cache)")
|
|
148
149
|
try:
|
|
149
150
|
json_data = requests.get(self.url).json()
|
|
@@ -164,9 +165,3 @@ class APIRequest:
|
|
|
164
165
|
``requests.Response``
|
|
165
166
|
"""
|
|
166
167
|
return requests.get(self.url)
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
# Run
|
|
170
|
-
###########################################################################
|
|
171
|
-
if __name__ == "__main__":
|
|
172
|
-
logger.setLevel(10)
|
absfuyu/util/json_method.py
CHANGED
|
@@ -3,35 +3,27 @@ Absfuyu: Json Method
|
|
|
3
3
|
--------------------
|
|
4
4
|
``.json`` file handling
|
|
5
5
|
|
|
6
|
-
Version:
|
|
7
|
-
Date updated:
|
|
6
|
+
Version: 5.0.0
|
|
7
|
+
Date updated: 25/02/2025 (dd/mm/yyyy)
|
|
8
8
|
"""
|
|
9
9
|
|
|
10
10
|
# Module level
|
|
11
|
-
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
12
|
__all__ = ["JsonFile"]
|
|
13
13
|
|
|
14
14
|
|
|
15
15
|
# Library
|
|
16
|
-
|
|
16
|
+
# ---------------------------------------------------------------------------
|
|
17
17
|
import json
|
|
18
18
|
from pathlib import Path
|
|
19
19
|
from typing import Any
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
# Function
|
|
23
|
-
###########################################################################
|
|
24
|
-
def load_json(json_file_location: Path): # Deprecated
|
|
25
|
-
"""Load JSON file"""
|
|
26
|
-
print("This function is deprecated as of version 3.0.0")
|
|
27
|
-
with open(Path(json_file_location), "r") as json_file:
|
|
28
|
-
data = json.load(json_file)
|
|
29
|
-
return data
|
|
21
|
+
from absfuyu.core import BaseClass
|
|
30
22
|
|
|
31
23
|
|
|
32
24
|
# Class
|
|
33
|
-
|
|
34
|
-
class JsonFile:
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
class JsonFile(BaseClass):
|
|
35
27
|
"""
|
|
36
28
|
``.json`` file handling
|
|
37
29
|
"""
|
|
@@ -59,9 +51,6 @@ class JsonFile:
|
|
|
59
51
|
def __str__(self) -> str:
|
|
60
52
|
return f"{self.__class__.__name__}({self.json_file_location.name})"
|
|
61
53
|
|
|
62
|
-
def __repr__(self) -> str:
|
|
63
|
-
return self.__str__()
|
|
64
|
-
|
|
65
54
|
def load_json(self) -> dict[Any, Any]:
|
|
66
55
|
"""
|
|
67
56
|
Load ``.json`` file
|
|
@@ -87,9 +76,3 @@ class JsonFile:
|
|
|
87
76
|
:type data: dict
|
|
88
77
|
"""
|
|
89
78
|
self.data = data
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
# Run
|
|
93
|
-
###########################################################################
|
|
94
|
-
if __name__ == "__main__":
|
|
95
|
-
pass
|
absfuyu/util/lunar.py
CHANGED
|
@@ -4,8 +4,8 @@ Absfuyu: Lunar calendar
|
|
|
4
4
|
-----------------------
|
|
5
5
|
Convert to lunar calendar
|
|
6
6
|
|
|
7
|
-
Version:
|
|
8
|
-
Date updated:
|
|
7
|
+
Version: 5.0.0
|
|
8
|
+
Date updated: 22/02/2025 (dd/mm/yyyy)
|
|
9
9
|
|
|
10
10
|
Source:
|
|
11
11
|
-------
|
|
@@ -14,18 +14,18 @@ https://www.informatik.uni-leipzig.de/~duc/amlich/AL.py
|
|
|
14
14
|
"""
|
|
15
15
|
|
|
16
16
|
# Module level
|
|
17
|
-
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
18
|
__all__ = ["LunarCalendar"]
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
# Library
|
|
22
|
-
|
|
22
|
+
# ---------------------------------------------------------------------------
|
|
23
23
|
import math
|
|
24
24
|
from datetime import date, datetime
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
# Class
|
|
28
|
-
|
|
28
|
+
# ---------------------------------------------------------------------------
|
|
29
29
|
class LunarCalendar:
|
|
30
30
|
"""Lunar Calendar"""
|
|
31
31
|
|
|
@@ -400,9 +400,3 @@ class LunarCalendar:
|
|
|
400
400
|
"""
|
|
401
401
|
today = datetime.now().date()
|
|
402
402
|
return cls(today.year, today.month, today.day).to_lunar()
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
# Run
|
|
406
|
-
###########################################################################
|
|
407
|
-
if __name__ == "__main__":
|
|
408
|
-
pass
|