reykit 1.1.69__py3-none-any.whl → 1.1.72__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.
reykit/rnet.py CHANGED
@@ -410,7 +410,7 @@ def download(url: str, path: str | None = None) -> str:
410
410
  ----------
411
411
  url : Download URL.
412
412
  path : Save path.
413
- - `None`, File name is `download`: and automatic judge file type.
413
+ - `None`: File name is get from response, or is 'download' join automatic judge file type.
414
414
 
415
415
  Returns
416
416
  -------
@@ -421,20 +421,21 @@ def download(url: str, path: str | None = None) -> str:
421
421
  response = request(url)
422
422
  content = response.content
423
423
 
424
- # Judge file type and path.
424
+ # File name.
425
425
  if path is None:
426
+ file_name = None
426
427
  Content_disposition = response.headers.get('Content-Disposition', '')
427
428
  if 'filename' in Content_disposition:
428
- file_name = search(
429
+ file_name: str | None = search(
429
430
  'filename=[\'"]?([^\\s\'"]+)',
430
431
  Content_disposition
431
432
  )
432
- else:
433
- file_name = None
434
433
  if file_name is None:
435
434
  file_type_obj = filetype_guess(content)
436
- file_name = 'download.' + file_type_obj.EXTENSION
437
- file_name = file_name or 'download'
435
+ if file_type_obj is not None:
436
+ file_name = 'download.' + file_type_obj.EXTENSION
437
+ else:
438
+ file_name = 'download'
438
439
  path = os_abspath(file_name)
439
440
 
440
441
  # Save.
reykit/ros.py CHANGED
@@ -22,6 +22,7 @@ from os import (
22
22
  remove as os_remove
23
23
  )
24
24
  from os.path import (
25
+ abspath as os_abspath,
25
26
  join as os_join,
26
27
  isfile as os_isfile,
27
28
  isdir as os_isdir,
@@ -38,13 +39,15 @@ from os.path import (
38
39
  )
39
40
  from shutil import copy as shutil_copy
40
41
  from pathlib import Path
41
- from json import JSONDecodeError
42
- from tomllib import loads as tomllib_loads
43
42
  from hashlib import md5 as hashlib_md5
43
+ from tomllib import loads as tomllib_loads
44
+ from json import JSONDecodeError
45
+ from filetype import guess as filetype_guess
44
46
  from tempfile import TemporaryFile, TemporaryDirectory
45
47
 
46
48
  from .rbase import Base, throw
47
49
  from .rdata import to_json
50
+ from .rnet import request
48
51
  from .rre import search, sub
49
52
  from .rsys import run_cmd
50
53
 
@@ -1980,10 +1983,10 @@ class FileCache(Base):
1980
1983
 
1981
1984
  Parameters
1982
1985
  ----------
1983
- md5 : File md5 value.
1986
+ md5 : File MD5 value.
1984
1987
  name : File name.
1985
- - `None`: Use md5 value.
1986
- copy : Do you want to copy file when exist md5 value file and not exist file name.
1988
+ - `None`: Use MD5 value.
1989
+ copy : Do you want to copy file when exist MD5 value file and not exist file name.
1987
1990
 
1988
1991
  Returns
1989
1992
  -------
@@ -2024,7 +2027,7 @@ class FileCache(Base):
2024
2027
  ----------
2025
2028
  source : Source file path or file data.
2026
2029
  name : File name.
2027
- - `None`: Use md5 value.
2030
+ - `None`: Use MD5 value.
2028
2031
  delete : When source is file path, whether delete original file.
2029
2032
 
2030
2033
  Returns
@@ -2069,6 +2072,47 @@ class FileCache(Base):
2069
2072
  return path
2070
2073
 
2071
2074
 
2075
+ def download(self, url: str, name: str | None = None) -> str:
2076
+ """
2077
+ Download file from URL.
2078
+
2079
+ Parameters
2080
+ ----------
2081
+ url : Download URL.
2082
+ name : File name.
2083
+ - `None`: Get from response, or is MD5 value join automatic judge file type.
2084
+
2085
+ Returns
2086
+ -------
2087
+ File absolute path.
2088
+ """
2089
+
2090
+ # Download.
2091
+ response = request(url)
2092
+ content = response.content
2093
+
2094
+ # File name.
2095
+ if name is None:
2096
+ Content_disposition = response.headers.get('Content-Disposition', '')
2097
+ if 'filename' in Content_disposition:
2098
+ name: str | None = search(
2099
+ 'filename=[\'"]?([^\\s\'"]+)',
2100
+ Content_disposition
2101
+ )
2102
+ if name is None:
2103
+ file_md5 = get_md5(content)
2104
+ file_type_obj = filetype_guess(content)
2105
+ if file_type_obj is not None:
2106
+ name = f'{file_md5}.{file_type_obj.EXTENSION}'
2107
+ else:
2108
+ name = file_md5
2109
+
2110
+ # Store.
2111
+ path = self.store(content, name)
2112
+
2113
+ return path
2114
+
2115
+
2072
2116
  def doc_to_docx(path: str, save_path: str | None = None) -> str:
2073
2117
  """
2074
2118
  Convert `DOC` file to `DOCX` file.
reykit/rschedule.py CHANGED
@@ -89,8 +89,6 @@ class Schedule(Base):
89
89
  'base.stats_schedule': 'stats_schedule'
90
90
  }
91
91
 
92
- self.notes: dict[str, str] = {}
93
-
94
92
 
95
93
  def pause(self) -> None:
96
94
  """
@@ -259,9 +257,6 @@ class Schedule(Base):
259
257
  **trigger_args
260
258
  )
261
259
 
262
- # Note.
263
- self.notes[job.id] = note
264
-
265
260
  return job
266
261
 
267
262
 
reykit/rtime.py CHANGED
@@ -58,7 +58,7 @@ def now(format_: Literal['time']) -> Time: ...
58
58
  def now(format_: Literal['datetime_str', 'date_str', 'time_str']) -> str: ...
59
59
 
60
60
  @overload
61
- def now(format_: Literal['timestamp']) -> int: ...
61
+ def now(format_: Literal['timestamp', 'timestamp_s']) -> int: ...
62
62
 
63
63
  def now(
64
64
  format_: Literal[
@@ -68,7 +68,8 @@ def now(
68
68
  'datetime_str',
69
69
  'date_str',
70
70
  'time_str',
71
- 'timestamp'
71
+ 'timestamp',
72
+ 'timestamp_s'
72
73
  ] = 'datetime'
73
74
  ) -> Datetime | Date | Time | str | int:
74
75
  """
@@ -84,6 +85,7 @@ def now(
84
85
  - `Literal['date_str']`: Return string in format `'%Y-%m-%d'`.
85
86
  - `Literal['time_str']`: Return string in foramt `'%H:%M:%S'`.
86
87
  - `Literal['timestamp']`: Return time stamp in milliseconds.
88
+ - `Literal['timestamp_s']`: Return time stamp in seconds.
87
89
 
88
90
  Returns
89
91
  -------
@@ -106,6 +108,8 @@ def now(
106
108
  return Datetime.now().strftime('%H:%M:%S')
107
109
  case 'timestamp':
108
110
  return int(time_time() * 1000)
111
+ case 'timestamp_s':
112
+ return int(time_time())
109
113
  case _:
110
114
  throw(ValueError, format_)
111
115
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: reykit
3
- Version: 1.1.69
3
+ Version: 1.1.72
4
4
  Summary: Kit method set.
5
5
  Project-URL: homepage, https://github.com/reyxbo/reykit/
6
6
  Author-email: Rey <reyxbo@163.com>
@@ -6,23 +6,23 @@ reykit/remail.py,sha256=l4HGKXdfHNBxyBT3YxeZyQhfecbElqTqSAGInwWhap8,6723
6
6
  reykit/rimage.py,sha256=lNN2iMpvSMqh-nPTpxrA9yHy43EA5WoYdxKYhqPwMgk,6154
7
7
  reykit/rlog.py,sha256=TRAWaVG9KTgzeNjN-FXkcvBmvq1IhICgawllQEGoUdg,25745
8
8
  reykit/rmonkey.py,sha256=Dj2GBzBDFXbo0Z-5f8Zep4dfbaIw1bo1FUmC31xvDuk,7929
9
- reykit/rnet.py,sha256=AfMUcAW26zNauW6PeS3GYkLJcJu_82g1tkZGnc--Qto,16848
9
+ reykit/rnet.py,sha256=rKCrIlQnU8yAEOIbnVz6NPKBOWb_RR2vFU1ibvNsxZo,16912
10
10
  reykit/rnum.py,sha256=PhG4V_BkVfCJUsbpMDN1umGZly1Hsus80TW8bpyBtyY,3653
11
- reykit/ros.py,sha256=Yi_mfYzVHwjjUZke0BNX7PKFLZpoT5NRyj5aDOSNQRU,46911
11
+ reykit/ros.py,sha256=TMP5vZvVqskeLv1oGoed5SJSIHbNUraaAgBbrWK4vYE,48219
12
12
  reykit/rrand.py,sha256=4VwooITgox54_GonELcJfcIpStDi-UJchpnyWKnyeIA,8606
13
13
  reykit/rre.py,sha256=1qva7xatKVE9qC2j7IujjXSM59qxHWwTYpiizFFQ8Xo,6024
14
- reykit/rschedule.py,sha256=FC_8mfF9mj7EmmcDDgtVPEt9X1DST_iwNK15SctFSws,14901
14
+ reykit/rschedule.py,sha256=HuQRSNF6yd397P9knIX9-z8Ii1tUXFUL_-zxTIkxir0,14804
15
15
  reykit/rstdout.py,sha256=yesWo7wIGablpyAu-2J2Gw11Qp3GdQjGICTyIcvLyt4,8200
16
16
  reykit/rsys.py,sha256=AP62KyN40flCeQJBclfJq8shachSAFT0LkVjiKsXkrw,24946
17
17
  reykit/rtable.py,sha256=UQ-JlwjssMR3gY1iY-VGQEKQ5_BZabpJy6TL7Fx19c4,12200
18
18
  reykit/rtask.py,sha256=NUTngUUDUZy3TqEHiuiKy17FcE0F1zS118KnKTsBjng,22838
19
19
  reykit/rtext.py,sha256=cWHy19lDcJvpX7LU95kmRVsDimpAUaz5TbKC1h83gB4,13254
20
- reykit/rtime.py,sha256=8QJ6YNiC0JUDiW1xc1tkzQUMPYOFT7d7dKCYRuYt9co,17635
20
+ reykit/rtime.py,sha256=lsSKaYFmYXlDN18yj2fLVTKSruzgygl8icW6_Fl42Xk,17807
21
21
  reykit/rwrap.py,sha256=FEmeK_fboJ-OyXeJf8bilc7U2ph8xIbZGNHb6fLCy2c,15063
22
22
  reykit/rzip.py,sha256=BGEONswuBZxQ-zcgd_xp2fcvYesC9AmKaaXWvnT3bTI,3456
23
23
  reykit/rdll/__init__.py,sha256=nLSb8onBm2ilyoxzpDzUeGfSCKwkLEesIhzK3LiJ8mk,701
24
24
  reykit/rdll/rdll_core.py,sha256=o6-rKcTQgxZQe0kD3GnwyNb3KL9IogzgCQNOmYLMm7A,5086
25
- reykit-1.1.69.dist-info/METADATA,sha256=j_h9WMxqDklZbv-Ch2SGAm7qWqW-nlLfqD_SUVVlWf4,1872
26
- reykit-1.1.69.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
- reykit-1.1.69.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
- reykit-1.1.69.dist-info/RECORD,,
25
+ reykit-1.1.72.dist-info/METADATA,sha256=nV_IYvPaBAOCJsP3qwHda5Panl8B0YlqxQIcNkxUNzU,1872
26
+ reykit-1.1.72.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
27
+ reykit-1.1.72.dist-info/licenses/LICENSE,sha256=UYLPqp7BvPiH8yEZduJqmmyEl6hlM3lKrFIefiD4rvk,1059
28
+ reykit-1.1.72.dist-info/RECORD,,