oafuncs 0.0.98.31__py3-none-any.whl → 0.0.98.33__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.
@@ -300,11 +300,13 @@ class ColorProgressBar:
300
300
  # 获取终端宽度
301
301
  try:
302
302
  term_width = self.bar_length or (shutil.get_terminal_size().columns if self._is_terminal else 80)
303
+ # print(f'Terminal width: {term_width}') # 调试输出
303
304
  except (AttributeError, OSError):
304
305
  term_width = 80 # 默认终端宽度
305
306
 
306
307
  # 确保有效宽度不小于最低限制
307
- effective_width = max(15, term_width - 40)
308
+ # effective_width = max(15, term_width - 40)
309
+ effective_width = max(15, int(term_width * 0.6)) # 保留40个字符用于其他信息
308
310
  if effective_width < 10:
309
311
  warnings.warn("Terminal width is too small for proper progress bar rendering.")
310
312
  effective_width = 10 # 设置最低宽度限制
@@ -1,18 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-25 16:22:52
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-26 19:21:31
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\_script\\data_interp.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
1
  from typing import List, Union
17
2
 
18
3
  import numpy as np
oafuncs/_script/email.py CHANGED
@@ -1,21 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-04 20:21:59
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-04 20:21:59
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\_script\\email.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
-
17
-
18
-
19
1
  import random
20
2
  import smtplib
21
3
  from email.header import Header
@@ -26,7 +8,6 @@ from rich import print
26
8
 
27
9
  __all__ = ["send"]
28
10
 
29
-
30
11
  def _email_info():
31
12
  email_dict = {
32
13
  "liukun0312@vip.qq.com": [4, 13, -10, 2, -10, 4, -7, -8, 8, -1, 3, -2, -11, -6, -9, -7],
@@ -1,18 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-05 14:00:50
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-05 14:00:50
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\_script\\netcdf_modify.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
1
  import os
17
2
 
18
3
  import netCDF4 as nc
@@ -1,18 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-03-21 10:02:32
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-03-21 10:02:33
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\_script\\replace_file_concent.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
1
  import datetime
17
2
  import os
18
3
  import re
oafuncs/oa_cmap.py CHANGED
@@ -258,10 +258,17 @@ def get(colormap_name: Optional[str] = None, show_available: bool = False) -> Op
258
258
  "cool_1": ["#4e00b3", "#0000FF", "#00c0ff", "#a1d3ff", "#DCDCDC"],
259
259
  "warm_1": ["#DCDCDC", "#FFD39B", "#FF8247", "#FF0000", "#FF5F9E"],
260
260
  # ---------------------------------------------------------------------------
261
+ # suitable for diverging color maps, wind vector
261
262
  "diverging_2": ["#4A235A", "#1F618D", "#1ABC9C", "#A9DFBF", "#F2F3F4", "#FDEBD0", "#F5B041", "#E74C3C", "#78281F"],
262
263
  "cool_2": ["#4A235A", "#1F618D", "#1ABC9C", "#A9DFBF", "#F2F3F4"],
263
264
  "warm_2": ["#F2F3F4", "#FDEBD0", "#F5B041", "#E74C3C", "#78281F"],
264
265
  # ---------------------------------------------------------------------------
266
+ "diverging_3": ["#1a66f2", "#5DADE2", "#48C9B0", "#A9DFBF", "#F2F3F4", "#FFDAB9", "#FF9E80", "#FF6F61", "#FF1744"],
267
+ "cool_3": ["#1a66f2", "#5DADE2", "#48C9B0", "#A9DFBF", "#F2F3F4"],
268
+ "warm_3": ["#F2F3F4", "#FFDAB9", "#FF9E80", "#FF6F61", "#FF1744"],
269
+ # ---------------------------------------------------------------------------
270
+ "diverging_4": ["#5DADE2", "#A2D9F7", "#D6EAF8", "#F2F3F4", "#FADBD8", "#F1948A", "#E74C3C"],
271
+ # ----------------------------------------------------------------------------
265
272
  "colorful_1": ["#6d00db", "#9800cb", "#F2003C", "#ff4500", "#ff7f00", "#FE28A2", "#FFC0CB", "#DDA0DD", "#40E0D0", "#1a66f2", "#00f7fb", "#8fff88", "#E3FF00"],
266
273
  }
267
274
 
oafuncs/oa_date.py CHANGED
@@ -1,20 +1,6 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-03-27 16:56:57
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-04 12:58:15
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_date.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
1
  import calendar
17
2
  import datetime
3
+ import functools
18
4
  from typing import List, Optional
19
5
 
20
6
  from rich import print
@@ -64,15 +50,16 @@ def hour_range(start_time: str, end_time: str, hour_interval: int = 6) -> List[s
64
50
  date_s += datetime.timedelta(hours=hour_interval)
65
51
  return date_list
66
52
 
53
+
67
54
  def adjust_time(base_time: str, time_delta: int, delta_unit: str = "hours", output_format: Optional[str] = None) -> str:
68
55
  """
69
56
  Adjust a given base time by adding a specified time delta.
70
57
 
71
58
  Args:
72
- base_time (str): Base time in the format "yyyymmdd" to "yyyymmddHHMMSS".
73
- Missing parts are assumed to be "0".
59
+ base_time (str): Base time in the format "yyyy" to "yyyymmddHHMMSS".
60
+ Missing parts are padded with appropriate defaults.
74
61
  time_delta (int): The amount of time to add.
75
- delta_unit (str): The unit of time to add ("seconds", "minutes", "hours", "days").
62
+ delta_unit (str): The unit of time to add ("seconds", "minutes", "hours", "days", "months", "years").
76
63
  output_format (str, optional): Custom output format for the adjusted time. Defaults to None.
77
64
 
78
65
  Returns:
@@ -84,17 +71,31 @@ def adjust_time(base_time: str, time_delta: int, delta_unit: str = "hours", outp
84
71
  >>> adjust_time("20240101000000", 2, "hours", "%Y-%m-%d %H:%M:%S")
85
72
  '2024-01-01 02:00:00'
86
73
  >>> adjust_time("20240101000000", 30, "minutes")
87
- '2024-01-01 00:30:00'
74
+ '20240101003000'
88
75
  """
89
76
  # Normalize the input time to "yyyymmddHHMMSS" format
90
77
  time_format = "%Y%m%d%H%M%S"
91
- if len(base_time) == 4:
92
- base_time += "0101"
93
- elif len(base_time) == 6:
94
- base_time += "01"
95
- base_time = base_time.ljust(14, "0")
96
78
 
97
- time_obj = datetime.datetime.strptime(base_time, time_format)
79
+ # Pad the time string to full format
80
+ if len(base_time) == 4: # yyyy
81
+ base_time += "0101000000"
82
+ elif len(base_time) == 6: # yyyymm
83
+ base_time += "01000000"
84
+ elif len(base_time) == 8: # yyyymmdd
85
+ base_time += "000000"
86
+ elif len(base_time) == 10: # yyyymmddhh
87
+ base_time += "0000"
88
+ elif len(base_time) == 12: # yyyymmddhhmm
89
+ base_time += "00"
90
+ elif len(base_time) == 14: # yyyymmddhhmmss
91
+ pass # Already complete
92
+ else:
93
+ raise ValueError(f"Invalid base_time format. Expected 4-14 digits, got {len(base_time)}")
94
+
95
+ try:
96
+ time_obj = datetime.datetime.strptime(base_time, time_format)
97
+ except ValueError as e:
98
+ raise ValueError(f"Invalid date format: {base_time}. Error: {e}")
98
99
 
99
100
  # Add the specified amount of time
100
101
  if delta_unit == "seconds":
@@ -114,8 +115,18 @@ def adjust_time(base_time: str, time_delta: int, delta_unit: str = "hours", outp
114
115
  time_obj = time_obj.replace(year=year, month=month, day=day)
115
116
  elif delta_unit == "years":
116
117
  # Handle year addition separately
117
- year = time_obj.year + time_delta
118
- time_obj = time_obj.replace(year=year)
118
+ try:
119
+ year = time_obj.year + time_delta
120
+ # Handle leap year edge case for Feb 29
121
+ if time_obj.month == 2 and time_obj.day == 29:
122
+ if not calendar.isleap(year):
123
+ time_obj = time_obj.replace(year=year, day=28)
124
+ else:
125
+ time_obj = time_obj.replace(year=year)
126
+ else:
127
+ time_obj = time_obj.replace(year=year)
128
+ except ValueError as e:
129
+ raise ValueError(f"Invalid year calculation: {e}")
119
130
  else:
120
131
  raise ValueError("Invalid time unit. Use 'seconds', 'minutes', 'hours', 'days', 'months', or 'years'.")
121
132
 
@@ -123,19 +134,9 @@ def adjust_time(base_time: str, time_delta: int, delta_unit: str = "hours", outp
123
134
  if output_format:
124
135
  return time_obj.strftime(output_format)
125
136
  else:
126
- if delta_unit == "seconds":
127
- default_format = "%Y%m%d%H%M%S"
128
- elif delta_unit == "minutes":
129
- default_format = "%Y%m%d%H%M"
130
- elif delta_unit == "hours":
131
- default_format = "%Y%m%d%H"
132
- elif delta_unit == "days":
133
- default_format = "%Y%m%d"
134
- elif delta_unit == "months":
135
- default_format = "%Y%m"
136
- elif delta_unit == "years":
137
- default_format = "%Y"
138
- return time_obj.strftime(default_format)
137
+ # Use default format based on delta_unit
138
+ format_map = {"seconds": "%Y%m%d%H%M%S", "minutes": "%Y%m%d%H%M%S", "hours": "%Y%m%d%H", "days": "%Y%m%d", "months": "%Y%m", "years": "%Y"}
139
+ return time_obj.strftime(format_map[delta_unit])
139
140
 
140
141
 
141
142
  class timeit:
@@ -154,26 +155,29 @@ class timeit:
154
155
  Example:
155
156
  @timeit(log_to_file=True, display_time=True)
156
157
  def example_function():
157
- # Simulate some work
158
+ import time
158
159
  time.sleep(2)
159
160
  """
160
161
 
161
- def __init__(self, func, log_to_file: bool = False, display_time: bool = True):
162
- self.func = func
162
+ def __init__(self, log_to_file: bool = False, display_time: bool = True):
163
163
  self.log_to_file = log_to_file
164
164
  self.display_time = display_time
165
165
 
166
- def __call__(self, *args, **kwargs):
167
- start_time = datetime.datetime.now()
168
- result = self.func(*args, **kwargs)
169
- end_time = datetime.datetime.now()
170
- elapsed_time = (end_time - start_time).total_seconds()
166
+ def __call__(self, func):
167
+ @functools.wraps(func)
168
+ def wrapper(*args, **kwargs):
169
+ start_time = datetime.datetime.now()
170
+ result = func(*args, **kwargs)
171
+ end_time = datetime.datetime.now()
172
+ elapsed_time = (end_time - start_time).total_seconds()
173
+
174
+ if self.display_time:
175
+ print(f"[bold green]Function '{func.__name__}' executed in {elapsed_time:.2f} seconds.[/bold green]")
171
176
 
172
- if self.display_time:
173
- print(f"[bold green]Function '{self.func.__name__}' executed in {elapsed_time:.2f} seconds.[/bold green]")
177
+ if self.log_to_file:
178
+ with open("execution_time.log", "a", encoding="utf-8") as log_file:
179
+ log_file.write(f"{datetime.datetime.now()} - Function '{func.__name__}' executed in {elapsed_time:.2f} seconds.\n")
174
180
 
175
- if self.log_to_file:
176
- with open("execution_time.log", "a") as log_file:
177
- log_file.write(f"{datetime.datetime.now()} - Function '{self.func.__name__}' executed in {elapsed_time:.2f} seconds.\n")
181
+ return result
178
182
 
179
- return result
183
+ return wrapper
@@ -1,17 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2024-09-17 16:09:20
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2024-12-26 08:09:01
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\__init__.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.11
14
- """
15
1
 
16
2
  # from .love_ocean import sign as love_ocean
17
3
  # from .meteorological_home import sign as meteorological_home
@@ -719,7 +719,7 @@ class _HycomDownloader:
719
719
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3]
720
720
  # print(f"{timestamp} - INFO - ", end="") # Output log prefix without newline
721
721
  # print("[bold #3dfc40]Success")
722
- print(f"{timestamp} - RESULT - [bold #3dfc40]Success")
722
+ print(f"{timestamp} - INFO - [bold #3dfc40]Success")
723
723
  return
724
724
 
725
725
  except Exception as e:
@@ -733,10 +733,11 @@ class _HycomDownloader:
733
733
  logging.error(f"Giving up on {file_name}")
734
734
  self.count["fail"] += 1
735
735
  count_dict["fail"] += 1
736
+ count_dict["fail_data_list"].append(file_name)
736
737
  timestamp = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S,%f")[:-3]
737
738
  # print(f"{timestamp} - ERROR - ", end="")
738
739
  # print("[bold red]Failed")
739
- print(f"{timestamp} - RESULT - [bold red]Failure")
740
+ print(f"{timestamp} - INFO - [bold red]Failure")
740
741
  return
741
742
 
742
743
  async def run(self):
@@ -1091,7 +1092,7 @@ def download(
1091
1092
  end_time += "21"
1092
1093
 
1093
1094
  global count_dict
1094
- count_dict = {"success": 0, "fail": 0, "skip": 0, "no_data": 0, "total": 0, "no_data_list": []}
1095
+ count_dict = {"success": 0, "fail": 0, "skip": 0, "no_data": 0, "total": 0, "no_data_list": [], "fail_data_list": []}
1095
1096
 
1096
1097
  global fsize_dict
1097
1098
  fsize_dict = {}
@@ -1162,6 +1163,8 @@ def download(
1162
1163
  print("[bold #ecdbfe]=" * mark_len)
1163
1164
  if count_dict["fail"] > 0:
1164
1165
  print("[bold #be5528]Please try again to download the failed data later.")
1166
+ for fail_data in count_dict["fail_data_list"]:
1167
+ print(f"[bold #d81b60]{fail_data}")
1165
1168
  if count_dict["no_data"] > 0:
1166
1169
  print(f"[bold #f90000]{count_dict['no_data']} data entries do not exist in any dataset or version.")
1167
1170
  for no_data in count_dict["no_data_list"]:
@@ -1,20 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-17 15:16:02
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-17 15:16:04
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\hycom_3hourly copy.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
-
17
-
18
1
  import asyncio
19
2
  import datetime
20
3
  import logging
oafuncs/oa_down/idm.py CHANGED
@@ -1,20 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-03-27 16:51:26
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-07 13:38:27
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\idm.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
-
17
-
18
1
  import datetime
19
2
  import os
20
3
  from subprocess import call
@@ -1,18 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2024-11-28 10:42:56
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-01-05 10:51:42
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\literature.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
1
  import os
17
2
  import re
18
3
  import time
@@ -1,18 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-17 13:59:14
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-17 14:00:38
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\read_proxy.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
-
16
1
  import threading
17
2
  from queue import Queue
18
3
  import random
@@ -1,17 +1,3 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2024-12-26 08:06:34
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2024-12-26 08:06:34
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\user_agent.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
1
  import os
16
2
  import random
17
3