absfuyu 4.1.0__py3-none-any.whl → 4.2.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.

Potentially problematic release.


This version of absfuyu might be problematic. Click here for more details.

absfuyu/__init__.py CHANGED
@@ -22,7 +22,7 @@ Using in cmd (`absfuyu[cli]` required):
22
22
  __title__ = "absfuyu"
23
23
  __author__ = "AbsoluteWinter"
24
24
  __license__ = "MIT License"
25
- __version__ = "4.1.0"
25
+ __version__ = "4.2.0"
26
26
  __all__ = [
27
27
  "core",
28
28
  "config",
absfuyu/cli/__init__.py CHANGED
@@ -3,8 +3,8 @@ ABSFUYU
3
3
  -------
4
4
  COMMAND LINE INTERFACE
5
5
 
6
- Version: 1.0.0
7
- Date updated: 14/04/2024 (dd/mm/yyyy)
6
+ Version: 1.1.0
7
+ Date updated: 09/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
10
10
  __all__ = ["cli"]
@@ -19,6 +19,7 @@ from absfuyu.cli.color import COLOR
19
19
  from absfuyu.cli.config_group import config_group
20
20
  from absfuyu.cli.do_group import do_group
21
21
  from absfuyu.cli.game_group import game_group
22
+ from absfuyu.cli.tool_group import tool_group
22
23
 
23
24
  # Color stuff
24
25
  colorama.init(autoreset=True)
@@ -48,4 +49,5 @@ def cli() -> None:
48
49
  cli.add_command(config_group)
49
50
  cli.add_command(do_group)
50
51
  cli.add_command(game_group)
52
+ cli.add_command(tool_group)
51
53
  cli.add_command(version)
absfuyu/cli/do_group.py CHANGED
@@ -3,14 +3,13 @@ ABSFUYU CLI
3
3
  -----------
4
4
  Do
5
5
 
6
- Version: 1.3.0
7
- Date updated: 01/02/2025 (dd/mm/yyyy)
6
+ Version: 1.4.0
7
+ Date updated: 07/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
10
10
  __all__ = ["do_group"]
11
11
 
12
12
  import subprocess
13
- from typing import Literal
14
13
 
15
14
  import click
16
15
 
@@ -18,7 +17,7 @@ from absfuyu import __title__
18
17
  from absfuyu.cli.color import COLOR
19
18
  from absfuyu.core import __package_feature__
20
19
  from absfuyu.general.human import Human2
21
- from absfuyu.tools.checksum import checksum_operation
20
+ from absfuyu.tools.shutdownizer import ShutDownizer
22
21
  from absfuyu.util.zipped import Zipper
23
22
  from absfuyu.version import PkgVersion
24
23
 
@@ -82,7 +81,11 @@ def fs(date: str, number_string: str) -> None:
82
81
  @click.command(name="info")
83
82
  @click.argument("date", type=str)
84
83
  def info(date: str) -> None:
85
- """Day info"""
84
+ """
85
+ Day info, format: yyyymmdd
86
+
87
+ Remake this
88
+ """
86
89
 
87
90
  instance = Human2(date)
88
91
  print(instance.info())
@@ -98,38 +101,11 @@ def unzip_files_in_dir(dir: str) -> None:
98
101
  print("Done")
99
102
 
100
103
 
101
- @click.command(name="checksum")
102
- @click.argument("file_path", type=str)
103
- @click.option(
104
- "--hashmode",
105
- "-m",
106
- "hash_mode",
107
- type=click.Choice(["md5", "sha1", "sha256", "sha512"]),
108
- default="sha256",
109
- show_default=True,
110
- help="Hash mode",
111
- )
112
- @click.option(
113
- "--compare",
114
- "-c",
115
- "hash_to_compare",
116
- type=str,
117
- default=None,
118
- show_default=True,
119
- help="Hash to compare",
120
- )
121
- def file_checksum(
122
- file_path: str,
123
- hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"],
124
- hash_to_compare: str,
125
- ) -> None:
126
- """Checksum for file"""
127
-
128
- res = checksum_operation(file_path, hash_mode=hash_mode)
129
- if hash_to_compare:
130
- print(res == hash_to_compare)
131
- else:
132
- print(res)
104
+ @click.command(name="shutdown")
105
+ def os_shutdown() -> None:
106
+ """Shutdown"""
107
+ engine = ShutDownizer()
108
+ engine.shutdown()
133
109
 
134
110
 
135
111
  @click.group(name="do")
@@ -144,4 +120,4 @@ do_group.add_command(advice)
144
120
  do_group.add_command(fs)
145
121
  do_group.add_command(info)
146
122
  do_group.add_command(unzip_files_in_dir)
147
- do_group.add_command(file_checksum)
123
+ do_group.add_command(os_shutdown)
@@ -0,0 +1,136 @@
1
+ """
2
+ ABSFUYU CLI
3
+ -----------
4
+ Tool
5
+
6
+ Version: 1.0.0
7
+ Date updated: 10/02/2025 (dd/mm/yyyy)
8
+ """
9
+
10
+ __all__ = ["tool_group"]
11
+
12
+ from typing import Literal
13
+
14
+ import click
15
+
16
+ from absfuyu.tools.checksum import Checksum
17
+ from absfuyu.tools.converter import Base64EncodeDecode, Text2Chemistry
18
+
19
+
20
+ @click.command(name="checksum")
21
+ @click.argument("file_path", type=str)
22
+ @click.option(
23
+ "--hashmode",
24
+ "-m",
25
+ "hash_mode",
26
+ type=click.Choice(["md5", "sha1", "sha256", "sha512"]),
27
+ default="sha256",
28
+ show_default=True,
29
+ help="Hash mode",
30
+ )
31
+ @click.option(
32
+ "--save-result",
33
+ "-s",
34
+ "save_result",
35
+ type=bool,
36
+ default=False,
37
+ is_flag=True,
38
+ show_default=True,
39
+ help="Save checksum result to file",
40
+ )
41
+ @click.option(
42
+ "--recursive",
43
+ "-r",
44
+ "recursive_mode",
45
+ type=bool,
46
+ default=False,
47
+ is_flag=True,
48
+ show_default=True,
49
+ help="Do checksum for every file in the folder (including child folder)",
50
+ )
51
+ @click.option(
52
+ "--compare",
53
+ "-c",
54
+ "hash_to_compare",
55
+ type=str,
56
+ default=None,
57
+ show_default=True,
58
+ help="Hash to compare",
59
+ )
60
+ def file_checksum(
61
+ file_path: str,
62
+ hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"],
63
+ save_result: bool,
64
+ recursive_mode: bool,
65
+ hash_to_compare: str,
66
+ ) -> None:
67
+ """Checksum for file/directory"""
68
+ # print(hash_mode, save_result, recursive_mode)
69
+ instance = Checksum(file_path, hash_mode=hash_mode, save_result_to_file=save_result)
70
+ res = instance.checksum(recursive=recursive_mode)
71
+ if hash_to_compare:
72
+ print(res == hash_to_compare)
73
+ else:
74
+ print(res)
75
+
76
+
77
+ @click.command(name="t2c")
78
+ @click.argument("text", type=str)
79
+ def text2chem(text: str) -> None:
80
+ """Convert text into chemistry symbol"""
81
+ engine = Text2Chemistry()
82
+ out = engine.convert(text)
83
+ print(Text2Chemistry.beautify_result(out))
84
+
85
+
86
+ @click.command(name="e")
87
+ @click.argument("text", type=str)
88
+ def base64encode(text: str) -> None:
89
+ """Convert text to base64"""
90
+ print(Base64EncodeDecode.encode(text))
91
+
92
+
93
+ @click.command(name="d")
94
+ @click.argument("text", type=str)
95
+ def base64decode(text: str) -> None:
96
+ """Convert base64 to text"""
97
+ print(Base64EncodeDecode.decode(text))
98
+
99
+
100
+ @click.command(name="img")
101
+ @click.option(
102
+ "--data-tag",
103
+ "-d",
104
+ "data_tag",
105
+ type=bool,
106
+ default=False,
107
+ is_flag=True,
108
+ show_default=True,
109
+ help="Add data tag before base64 string",
110
+ )
111
+ @click.argument("img_path", type=str)
112
+ def base64convert_img(img_path: str, data_tag: bool) -> None:
113
+ """Convert img to base64"""
114
+ print(Base64EncodeDecode.encode_image(img_path, data_tag=data_tag))
115
+
116
+
117
+ @click.group(name="b64")
118
+ def base64_group():
119
+ """Base64 encode decode"""
120
+ pass
121
+
122
+
123
+ base64_group.add_command(base64encode)
124
+ base64_group.add_command(base64decode)
125
+ base64_group.add_command(base64convert_img)
126
+
127
+
128
+ @click.group(name="tool")
129
+ def tool_group() -> None:
130
+ """Tools"""
131
+ pass
132
+
133
+
134
+ tool_group.add_command(file_checksum)
135
+ tool_group.add_command(base64_group)
136
+ tool_group.add_command(text2chem)
absfuyu/core.py CHANGED
@@ -3,8 +3,8 @@ Absfuyu: Core
3
3
  -------------
4
4
  Contain type hints and other stuffs
5
5
 
6
- Version: 2.3.0
7
- Date updated: 01/02/2025 (dd/mm/yyyy)
6
+ Version: 2.3.2
7
+ Date updated: 11/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
10
10
  # Module Package
@@ -18,14 +18,13 @@ __all__ = [
18
18
  "DATA_PATH",
19
19
  ]
20
20
 
21
- __package_feature__ = ["beautiful", "extra", "res", "full", "dev"]
21
+ __package_feature__ = ["beautiful", "extra", "full", "dev"]
22
22
 
23
23
 
24
24
  # Library
25
25
  ###########################################################################
26
26
  from importlib import import_module
27
27
  from importlib.resources import files
28
- from typing import Iterable
29
28
 
30
29
 
31
30
  class CLITextColor:
@@ -54,5 +53,5 @@ try:
54
53
  tqdm = import_module("tqdm").tqdm
55
54
  except ModuleNotFoundError:
56
55
 
57
- def tqdm(iterable: Iterable, **kwargs):
56
+ def tqdm(iterable, **kwargs):
58
57
  return iterable
@@ -1,6 +1,7 @@
1
1
  """
2
2
  Absfuyu: Extension
3
3
  ------------------
4
+ Features that require additional libraries
4
5
 
5
6
  Version: 1.0.1
6
7
  Date updated: 24/11/2023 (dd/mm/yyyy)
@@ -26,9 +26,9 @@ from absfuyu.logger import logger
26
26
  ###########################################################################
27
27
  _EXTERNAL_DATA = {
28
28
  "chemistry.json": "https://raw.githubusercontent.com/Bowserinator/Periodic-Table-JSON/master/PeriodicTableJSON.json",
29
- "countries.json": "https://github.com/dr5hn/countries-states-cities-database/blob/master/countries.json",
30
29
  "tarot.json": "https://raw.githubusercontent.com/dariusk/corpora/master/data/divination/tarot_interpretations.json",
31
30
  "word_list.json": "https://raw.githubusercontent.com/dwyl/english-words/master/words_dictionary.json",
31
+ # "countries.json": "https://raw.githubusercontent.com/dr5hn/countries-states-cities-database/refs/heads/master/json/countries.json",
32
32
  }
33
33
 
34
34
 
@@ -37,6 +37,7 @@ _EXTERNAL_DATA = {
37
37
  class DataList:
38
38
  CHEMISTRY = files("absfuyu.pkg_data").joinpath("chemistry.pkl")
39
39
  TAROT = files("absfuyu.pkg_data").joinpath("tarot.pkl")
40
+ PASSWORDLIB = files("absfuyu.pkg_data").joinpath("passwordlib_lzma.pkl")
40
41
 
41
42
 
42
43
  class PkgData:
Binary file
absfuyu/tools/checksum.py CHANGED
@@ -3,13 +3,13 @@ Absufyu: Checksum
3
3
  -----------------
4
4
  Check MD5, SHA256, ...
5
5
 
6
- Version: 1.0.0
7
- Date updated: 01/02/2025 (dd/mm/yyyy)
6
+ Version: 1.1.1
7
+ Date updated: 05/02/2025 (dd/mm/yyyy)
8
8
  """
9
9
 
10
10
  # Module level
11
11
  ###########################################################################
12
- __all__ = ["checksum_operation"]
12
+ __all__ = ["Checksum", "checksum_operation"]
13
13
 
14
14
 
15
15
  # Library
@@ -18,9 +18,13 @@ import hashlib
18
18
  from pathlib import Path
19
19
  from typing import Literal
20
20
 
21
+ from absfuyu.core import tqdm
21
22
 
22
23
  # Function
23
24
  ###########################################################################
25
+
26
+
27
+ # Deprecated
24
28
  def checksum_operation(
25
29
  file: Path | str,
26
30
  hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"] = "sha256",
@@ -38,9 +42,6 @@ def checksum_operation(
38
42
  hash_engine = hashlib.md5()
39
43
 
40
44
  with open(Path(file), "rb") as f:
41
- # Read and hash the file in 4K chunks. Reading the whole
42
- # file at once might consume a lot of memory if it is
43
- # large.
44
45
  while True:
45
46
  data = f.read(4096)
46
47
  if len(data) == 0:
@@ -50,6 +51,103 @@ def checksum_operation(
50
51
  return hash_engine.hexdigest()
51
52
 
52
53
 
54
+ class Checksum:
55
+ def __init__(
56
+ self,
57
+ path: str | Path,
58
+ hash_mode: str | Literal["md5", "sha1", "sha256", "sha512"] = "sha256",
59
+ save_result_to_file: bool = False,
60
+ ) -> None:
61
+ """Checksum engine
62
+
63
+ Parameters
64
+ ----------
65
+ path : str | Path
66
+ Path to file/directory to perform checksum
67
+ hash_mode : str | Literal["md5", "sha1", "sha256", "sha512"], optional
68
+ Hash mode, by default "sha256"
69
+ save_result_to_file : bool, optional
70
+ Save checksum result(s) to file, by default False
71
+ """
72
+ self.path = Path(path)
73
+ self.hash_mode = hash_mode
74
+ self.save_result_to_file = save_result_to_file
75
+ self.checksum_result_file_name = "checksum_results.txt"
76
+
77
+ def _get_hash_engine(self):
78
+ hash_mode = self.hash_mode
79
+ if hash_mode.lower() == "md5":
80
+ hash_engine = hashlib.md5()
81
+ elif hash_mode.lower() == "sha1":
82
+ hash_engine = hashlib.sha1()
83
+ elif hash_mode.lower() == "sha256":
84
+ hash_engine = hashlib.sha256()
85
+ elif hash_mode.lower() == "sha512":
86
+ hash_engine = hashlib.sha512()
87
+ else:
88
+ hash_engine = hashlib.md5()
89
+ return hash_engine
90
+
91
+ def _checksum_operation(
92
+ self,
93
+ file: Path | str,
94
+ ) -> str:
95
+ """This performs checksum"""
96
+
97
+ hash_engine = self._get_hash_engine().copy()
98
+ with open(Path(file), "rb") as f:
99
+ # Read and hash the file in 4K chunks. Reading the whole
100
+ # file at once might consume a lot of memory if it is
101
+ # large.
102
+ while True:
103
+ data = f.read(4096)
104
+ if len(data) == 0:
105
+ break
106
+ else:
107
+ hash_engine.update(data)
108
+ return hash_engine.hexdigest() # type: ignore
109
+
110
+ def checksum(self, recursive: bool = True) -> str:
111
+ """Perform checksum
112
+
113
+ Parameters
114
+ ----------
115
+ recursive : bool, optional
116
+ Do checksum for every file in the folder (including child folder), by default True
117
+
118
+ Returns
119
+ -------
120
+ str
121
+ Checksum hash
122
+ """
123
+ if self.path.absolute().is_dir(): # Dir
124
+ new_path = self.path.joinpath(self.checksum_result_file_name)
125
+ # List of files
126
+ if recursive:
127
+ file_list: list[Path] = [
128
+ x for x in self.path.glob("**/*") if x.is_file()
129
+ ]
130
+ else:
131
+ file_list = [x for x in self.path.glob("*") if x.is_file()]
132
+
133
+ # Checksum
134
+ res = []
135
+ for x in tqdm(file_list, desc="Calculating hash", unit_scale=True):
136
+ name = x.relative_to(self.path)
137
+ res.append(f"{self._checksum_operation(x)} | {name}")
138
+ output = "\n".join(res)
139
+ else: # File
140
+ new_path = self.path.with_name(self.checksum_result_file_name)
141
+ output = self._checksum_operation(self.path)
142
+
143
+ # Save result
144
+ if self.save_result_to_file:
145
+ with open(new_path, "w", encoding="utf-8") as f:
146
+ f.write(output)
147
+
148
+ return output
149
+
150
+
53
151
  # Run
54
152
  ###########################################################################
55
153
  if __name__ == "__main__":
@@ -3,8 +3,8 @@ Absufyu: Converter
3
3
  ------------------
4
4
  Convert stuff
5
5
 
6
- Version: 1.3.0
7
- Date updated: 01/02/2025 (dd/mm/yyyy)
6
+ Version: 1.4.0
7
+ Date updated: 10/02/2025 (dd/mm/yyyy)
8
8
 
9
9
  Feature:
10
10
  --------
@@ -26,6 +26,7 @@ import re
26
26
  import string
27
27
  from itertools import chain, combinations
28
28
  from pathlib import Path
29
+ from typing import Self
29
30
 
30
31
  from absfuyu.core import CLITextColor
31
32
  from absfuyu.logger import logger
@@ -58,7 +59,7 @@ class Base64EncodeDecode:
58
59
  img_path : Path | str
59
60
  Path to image
60
61
  data_tag : bool, optional
61
- Add data tag before base64 string, by default False
62
+ Add data tag before base64 string, by default ``False``
62
63
 
63
64
  Returns
64
65
  -------
@@ -76,8 +77,6 @@ class Base64EncodeDecode:
76
77
  class ChemistryElement:
77
78
  """Chemistry Element"""
78
79
 
79
- _VERSION = (1, 1, 0)
80
-
81
80
  def __init__(self, name: str, number: int, symbol: str, atomic_mass: float) -> None:
82
81
  """
83
82
  name: element name
@@ -111,7 +110,7 @@ class ChemistryElement:
111
110
  }
112
111
 
113
112
  @classmethod
114
- def from_dict(cls, data: dict[str, str | int | float]) -> "ChemistryElement":
113
+ def from_dict(cls, data: dict[str, str | int | float]) -> Self:
115
114
  """
116
115
  Convert from ``dict`` data
117
116
 
@@ -159,7 +158,7 @@ class Text2Chemistry:
159
158
  # logger.debug(available)
160
159
  return base.difference(available)
161
160
 
162
- def convert(self, text: str) -> list[list[ChemistryElement]]:
161
+ def convert(self, text: str) -> list[list[ChemistryElement]] | list:
163
162
  """
164
163
  Convert text to chemistry symbol
165
164
 
@@ -231,6 +230,36 @@ class Text2Chemistry:
231
230
 
232
231
  return output
233
232
 
233
+ @staticmethod
234
+ def beautify_result(
235
+ result: list[list[ChemistryElement]] | list,
236
+ ) -> str: # Added in version 4.2.0
237
+ """Beautify the result from ``Text2Chemistry.convert()``
238
+
239
+ Parameters
240
+ ----------
241
+ result : list[list[ChemistryElement]] | list
242
+ Convert ``Text2Chemistry.convert()`` result
243
+
244
+ Returns
245
+ -------
246
+ str
247
+ Beautified output
248
+ """
249
+ if len(result) == 0:
250
+ res = "No possible combination"
251
+ else:
252
+ msg = []
253
+ for i, solution in enumerate(result, start=1):
254
+ msg.append(f"Option {i:02}: {', '.join([x.symbol for x in solution])}")
255
+ for x in solution:
256
+ msg.append(
257
+ f"{x.symbol} ({x.number}. {x.name} - {round(x.atomic_mass, 2)})"
258
+ )
259
+ msg.append("---")
260
+ res = "\n".join(msg)
261
+ return res
262
+
234
263
 
235
264
  class Str2Pixel:
236
265
  """Convert str into pixel"""