oafuncs 0.0.77__py2.py3-none-any.whl → 0.0.79__py2.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.
oafuncs/oa_down/test.py CHANGED
@@ -1,45 +1,45 @@
1
1
  #!/usr/bin/env python
2
2
  # coding=utf-8
3
- '''
3
+ """
4
4
  Author: Liu Kun && 16031215@qq.com
5
5
  Date: 2024-12-01 19:32:25
6
6
  LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2024-12-01 19:50:32
7
+ LastEditTime: 2024-12-10 11:16:36
8
8
  FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_down\\test.py
9
- Description:
9
+ Description:
10
10
  EditPlatform: vscode
11
11
  ComputerInfo: XPS 15 9510
12
12
  SystemInfo: Windows 11
13
13
  Python Version: 3.12
14
- '''
14
+ """
15
15
 
16
16
  import os
17
17
  import random
18
+ import re
18
19
 
19
- txtfile = r'E:\Code\Python\My_Funcs\OAFuncs\oafuncs\oa_down\User_Agent-list.txt'
20
20
 
21
- with open(txtfile, 'r') as f:
22
- lines = f.readlines()
23
- # 去掉换行符和空行
24
- lines = [line.strip() for line in lines if line.strip()]
25
- new_line = []
26
- for i in range(len(lines)):
27
- if '/' in lines[i]:
28
- new_line.append(lines[i])
29
- else:
30
- print(lines[i])
21
+ def is_valid_user_agent(user_agent):
22
+ # 简单的正则表达式来检查User Agent的格式
23
+ # 这个正则表达式检查User Agent是否包含常见的浏览器信息格式
24
+ pattern = re.compile(
25
+ r"^(?:(?:Mozilla|Opera|Chrome|Safari|Edg|OPR)/[\d.]+)"
26
+ r"(?:\s(?:\(.*?\)))?"
27
+ r"(?:\s(?:Gecko|AppleWebKit|KHTML, like Gecko|Version|Edge|OPR)/[\d.]+)?"
28
+ r"(?:\s.*?(?:rv:|Version/|Ubuntu|Macintosh|Windows|X11|Linux|CrOS|FreeBSD|OpenBSD|NetBSD|iPhone|iPad|iPod|Android|BlackBerry|BB10|Mobile|Symbian|Windows Phone|IEMobile|Opera Mini|Opera Mobi|UCBrowser|MQQBrowser|baiduboxapp|baidubrowser|Safari|Firefox|MSIE|Trident|Edge|EdgA|Chrome|CriOS|Vivaldi|Sleipnir|Midori|ELinks|Lynx|w3m|Arora|Epiphany|Konqueror|Dillo|Netscape|SeaMonkey|K-Meleon|Camino|Iceape|Galeon|GranParadiso|Iceweasel|Firefox|Fennec|Conkeror|PaleMoon|Uzbl|QupZilla|Otter|Waterfox|Basilisk|Cyberfox|PaleMoon|GNU IceCat|GNU IceWeasel|IceCat|IceWeasel|Seamonkey|Iceape|Firefox|Epiphany|Web|Safari|Android|Mobile|BlackBerry|BB10|Tablet|Silk|Kindle|FxiOS|Focus|SamsungBrowser|browser|AppleWebKit|Puffin|DuckDuckGo|YaBrowser|Yandex|Amigo|NokiaBrowser|OviBrowser|OneBrowser|Chrome|Firefox|Safari|OPR|Coast|Mercury|Silk|Skyfire|IEMobile|Bolt|Jasmine|NativeHost|Crosswalk|TizenBrowser|SailfishBrowser|SamsungBrowser|Silk-Accelerated|UCBrowser|Quark|XiaoMi|OnePlus|Vivo|Oppo|Realme|Meizu|Lenovo|Huawei|ZTE|Alcatel|Sony|Nokia|LG|HTC|Asus|Acer|Motorola|Samsung)/[\d.]+)?$"
29
+ )
31
30
 
32
- newtxtfile = r'E:\Code\Python\My_Funcs\OAFuncs\oafuncs\oa_down\ua_list_new.txt'
33
- """ with open(newtxtfile, 'w') as f:
34
- for line in new_line:
35
- f.write(line + '\n') """
31
+ # 使用正则表达式匹配User Agent字符串
32
+ if pattern.match(user_agent):
33
+ return True
34
+ else:
35
+ return False
36
36
 
37
37
 
38
38
  def get_ua():
39
39
  current_dir = os.path.dirname(os.path.abspath(__file__))
40
- ua_file_txt = os.path.join(current_dir, 'User_Agent-list.txt')
40
+ ua_file_txt = os.path.join(current_dir, "User_Agent-list.txt")
41
41
 
42
- with open(ua_file_txt, 'r') as f:
42
+ with open(ua_file_txt, "r") as f:
43
43
  ua_list = f.readlines()
44
44
  # 去掉换行符和空行
45
45
  ua_list = [line.strip() for line in ua_list if line.strip()]
@@ -47,9 +47,6 @@ def get_ua():
47
47
  return random.choice(ua_list)
48
48
 
49
49
 
50
- print(get_ua())
51
-
52
-
53
50
  def get_ua_org():
54
51
  ua_list = [
55
52
  "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 OPR/26.0.1656.60",
@@ -115,13 +112,40 @@ def get_ua_org():
115
112
  "NOKIA5700/UCWEB7.0.2.37/28/999",
116
113
  "Openwave/UCWEB7.0.2.37/28/999",
117
114
  "Openwave/UCWEB7.0.2.37/28/999",
118
-
119
115
  ]
120
- with open(newtxtfile, 'w') as f:
116
+ with open(newtxtfile, "w") as f:
121
117
  for line in ua_list:
122
- f.write(line + '\n')
118
+ f.write(line + "\n")
123
119
  # print(f'Using User-Agent: {ua}')
124
120
  ua = random.choice(ua_list)
125
121
  return ua
126
122
 
127
- # get_ua_org()
123
+
124
+ # get_ua_org()
125
+
126
+ if __name__ == "__main__":
127
+ txtfile = r"E:\Code\Python\My_Funcs\OAFuncs\oafuncs\oa_down\User_Agent-list.txt"
128
+
129
+ with open(txtfile, "r") as f:
130
+ lines = f.readlines()
131
+ # 去掉换行符和空行
132
+ lines = [line.strip() for line in lines if line.strip()]
133
+ """ new_line = []
134
+ for i in range(len(lines)):
135
+ if '/' in lines[i]:
136
+ new_line.append(lines[i])
137
+ else:
138
+ print(lines[i]) """
139
+
140
+ new_line = []
141
+ for line in lines:
142
+ if is_valid_user_agent(line):
143
+ # print(line)
144
+ new_line.append(line)
145
+ else:
146
+ print(f"Invalid User-Agent: {line}")
147
+
148
+ newtxtfile = r"E:\Code\Python\My_Funcs\OAFuncs\oafuncs\oa_down\ua_list_new.txt"
149
+ with open(newtxtfile, "w") as f:
150
+ for line in new_line:
151
+ f.write(line + "\n")
oafuncs/oa_draw.py CHANGED
@@ -26,10 +26,54 @@ import xarray as xr
26
26
  from cartopy.mpl.ticker import LatitudeFormatter, LongitudeFormatter
27
27
  from mpl_toolkits.axes_grid1 import make_axes_locatable
28
28
 
29
- __all__ = ['create_gif', 'xy2lonlat', 'plot_contourf', 'plot_contourf_lonlat', 'plot_quiver', 'plot_contourf_cartopy']
29
+ __all__ = ['fig_minus', 'create_gif', 'xy2lonlat', 'plot_contourf', 'plot_contourf_lonlat', 'plot_quiver', 'plot_contourf_cartopy']
30
30
 
31
31
  warnings.filterwarnings('ignore')
32
32
 
33
+ def fig_minus(ax_x=None, ax_y=None, cbar=None, decimal=None, add_space=False):
34
+ '''
35
+ Description: 将坐标轴刻度中的负号替换为减号
36
+
37
+ param {*} ax_x : x轴
38
+ param {*} ax_y : y轴
39
+ param {*} cbar : colorbar
40
+ param {*} decimal : 小数位数
41
+ param {*} add_space : 是否在非负数前面加空格
42
+
43
+ return {*} ax_x or ax_y or cbar
44
+ '''
45
+ if ax_x is not None:
46
+ current_ticks = ax_x.get_xticks()
47
+ if ax_y is not None:
48
+ current_ticks = ax_y.get_yticks()
49
+ if cbar is not None:
50
+ current_ticks = cbar.get_ticks()
51
+ # 先判断是否需要加空格,如果要,先获取需要加的索引
52
+ if add_space:
53
+ index = 0
54
+ for _, tick in enumerate(current_ticks):
55
+ if tick >= 0:
56
+ index = _
57
+ break
58
+ if decimal is not None:
59
+ # my_ticks = [(round(float(iii), decimal)) for iii in my_ticks]
60
+ current_ticks = [f"{val:.{decimal}f}" if val != 0 else "0" for val in current_ticks]
61
+
62
+ out_ticks = [f"{val}".replace("-", "\u2212") for val in current_ticks]
63
+ if add_space:
64
+ # 在非负数前面加两个空格
65
+ out_ticks[index:] = [" " + m for m in out_ticks[index:]]
66
+
67
+ if ax_x is not None:
68
+ ax_x.set_xticklabels(out_ticks)
69
+ return ax_x
70
+ if ax_y is not None:
71
+ ax_y.set_yticklabels(out_ticks)
72
+ return ax_y
73
+ if cbar is not None:
74
+ cbar.set_ticklabels(out_ticks)
75
+ return cbar
76
+
33
77
  # ** 将生成图片/已有图片制作成动图
34
78
 
35
79
 
oafuncs/oa_nc.py CHANGED
@@ -153,9 +153,14 @@ def merge5nc(file_list, var_name=None, dim_name=None, target_filename=None):
153
153
 
154
154
  参数:
155
155
  file_list:nc 文件路径列表
156
- var_name:要提取的变量名或变量名列表,默认为 None
156
+ var_name:要提取的变量名或变量名列表,默认为 None,表示提取所有变量
157
157
  dim_name:用于合并的维度名
158
158
  target_filename:合并后的目标文件名
159
+
160
+ example:
161
+ merge5nc(file_list, var_name='data', dim_name='time', target_filename='merged.nc')
162
+ merge5nc(file_list, var_name=['data1', 'data2'], dim_name='time', target_filename='merged.nc')
163
+ merge5nc(file_list, var_name=None, dim_name='time', target_filename='merged.nc')
159
164
  """
160
165
  # 初始化变量名列表
161
166
  var_names = None
@@ -208,67 +213,6 @@ def merge5nc(file_list, var_name=None, dim_name=None, target_filename=None):
208
213
  os.remove(target_filename)
209
214
  merged_data.to_netcdf(target_filename)
210
215
  print(f'File "{target_filename}" has been created.')
211
-
212
-
213
- def merge5nc_his1(file_list, var_name, dim_name, target_filename):
214
- """
215
- 批量提取 nc 文件中的某一变量,按照某一维度合并后写入新的 nc 文件。
216
-
217
- 参数:
218
- file_list:nc 文件路径列表
219
- var_name:要提取的变量名
220
- dim_name:用于合并的维度名
221
- target_filename:合并后的目标文件名
222
- example: merge5nc(file_list, 'sst', 'time', 'merged_data.nc')
223
- """
224
- data_list = []
225
- for i, file in enumerate(file_list):
226
- print(f"\rReading file {i + 1}/{len(file_list)}...", end="")
227
- ds = xr.open_dataset(file)
228
- var = ds[var_name]
229
- data_list.append(var)
230
- ds.close()
231
- print("\nMerging data...")
232
- data = xr.concat(data_list, dim=dim_name)
233
- print("Writing data to file...")
234
- if os.path.exists(target_filename):
235
- print("Warning: The target file already exists.")
236
- print("Removing existing file...")
237
- os.remove(target_filename)
238
- data.to_netcdf(target_filename)
239
-
240
-
241
- def merge5nc_vars_his1(file_list, var_names, dim_name, target_filename):
242
- """
243
- 批量提取 nc 文件中的两个变量,按照某一维度合并后写入新的 nc 文件。
244
-
245
- 参数:
246
- file_list:nc 文件路径列表
247
- var_names:要提取的变量名列表,例如 ['u', 'v']
248
- dim_name:用于合并的维度名
249
- target_filename:合并后的目标文件名
250
-
251
- example: merge5nc_vars(file_list, ['u', 'v'], 'time', 'merged_data.nc')
252
- """
253
- data_lists = [[] for _ in var_names]
254
- for i, file in enumerate(file_list):
255
- print(f"\rReading file {i + 1}/{len(file_list)}...", end="")
256
- ds = xr.open_dataset(file)
257
- for j, var_name in enumerate(var_names):
258
- var = ds[var_name]
259
- data_lists[j].append(var)
260
- ds.close()
261
- print("\nMerging data...")
262
- merged_data = {}
263
- for var_name, data_list in zip(var_names, data_lists):
264
- merged_data[var_name] = xr.concat(data_list, dim=dim_name)
265
- print("Writing data to file...")
266
- ds_merged = xr.Dataset(merged_data)
267
- if os.path.exists(target_filename):
268
- print("Warning: The target file already exists.")
269
- print("Removing existing file...")
270
- os.remove(target_filename)
271
- ds_merged.to_netcdf(target_filename)
272
216
 
273
217
 
274
218
  def modify_var_value(nc_file_path, variable_name, new_value):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: oafuncs
3
- Version: 0.0.77
3
+ Version: 0.0.79
4
4
  Summary: My short description for my project.
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -1,24 +1,24 @@
1
1
  oafuncs/__init__.py,sha256=2QiNjIIMtstD8y9HWlu23yiZGmmljkNUQknHEbnRwYI,673
2
2
  oafuncs/oa_cmap.py,sha256=LnHI6vMCoFFkMq4P3RgItmJ01Kx5MjjwwlhnaqhRLKI,7242
3
3
  oafuncs/oa_data.py,sha256=H9qZrUziOpc456iIL-1lBwSkBPApl2rlR-ajZg-mDMs,8119
4
- oafuncs/oa_draw.py,sha256=K5B_otgx7Bu5P6ZYipNt9C-uRI1w9oxwY1M1F0-kGuM,17329
4
+ oafuncs/oa_draw.py,sha256=R5KONDf3Rp8STXepawtYUTdbcfAK1h6AYh8xiOfac3g,18860
5
5
  oafuncs/oa_file.py,sha256=iHgv0CTH4k_7YUnQ8-qQbLoz_f2lUmVhzGWQ2LkPFP8,11624
6
6
  oafuncs/oa_help.py,sha256=ppNktmtNzs15R20MD1bM7yImlTQ_ngMwvoIglePOKXA,1000
7
- oafuncs/oa_nc.py,sha256=7KSONwujhElQo1dfuEE4EpVfaqnWyILdGvsdqpKrnMI,14666
7
+ oafuncs/oa_nc.py,sha256=7Fp65BJF_PtyaaxS5PS2apA-KkkQLhqh19Xlw__8XMo,12656
8
8
  oafuncs/oa_python.py,sha256=XPTP3o7zTFzfJR_YhsKfQksa3bSYwXsne9YxlJplCEA,3994
9
- oafuncs/oa_down/User_Agent-list.txt,sha256=j88ML0zwVibNj484ehurfZMX-PZ7G_1TwhwpcJZMIB0,884393
9
+ oafuncs/oa_down/User_Agent-list.txt,sha256=pazxSip8_lphEBOPHG902zmIBUg8sBKXgmqp_g6j_E4,661062
10
10
  oafuncs/oa_down/__init__.py,sha256=nY5X7gM1jw7DJxyooR2UJSq4difkw-flz2Ucr_OuDbA,540
11
- oafuncs/oa_down/hycom_3hourly.py,sha256=wVJgA8SBMr0RurTz7AkI8d5pJ4sj1oWl__cnSPATiCA,50343
11
+ oafuncs/oa_down/hycom_3hourly.py,sha256=pgONwoaLEKPQ4RjoFC4N2b7M6nIvKBgLNwk0XckfyRQ,56030
12
12
  oafuncs/oa_down/literature.py,sha256=dT3-7-beEzQ9mTP8LNV9Gf3q5Z1Pqqjc6FOS010HZeQ,17833
13
- oafuncs/oa_down/test.py,sha256=5sm73uduL0WO1GFv66ONIDLDAFavGz5qFoQpah5PbW8,8934
13
+ oafuncs/oa_down/test.py,sha256=0IQq3NjqfNr7KkyjS_U-a4mYu-r-E7gzawwo4IfEa6Y,10851
14
14
  oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,563
15
15
  oafuncs/oa_sign/meteorological.py,sha256=mLbupsZSq427HTfVbZMvIlFzDHwSzQAbK3X19o8anFY,6525
16
16
  oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
17
17
  oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
18
18
  oafuncs/oa_tool/__init__.py,sha256=IKOlqpWlb4cMDCtq2VKR_RTxQHDNqR_vfqqsOsp_lKQ,466
19
19
  oafuncs/oa_tool/email.py,sha256=4lJxV_KUzhxgLYfVwYTqp0qxRugD7fvsZkXDe5WkUKo,3052
20
- oafuncs-0.0.77.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
21
- oafuncs-0.0.77.dist-info/METADATA,sha256=66VNZ7aM1IFNy5H50VrBOMDlphZ0Mxr-gmBZVC6oAT4,22481
22
- oafuncs-0.0.77.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
23
- oafuncs-0.0.77.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
24
- oafuncs-0.0.77.dist-info/RECORD,,
20
+ oafuncs-0.0.79.dist-info/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
21
+ oafuncs-0.0.79.dist-info/METADATA,sha256=0fQiVoR8HZQfISZClpFTyPKLXiwnTVA8Iq2Qvzxgj7U,22481
22
+ oafuncs-0.0.79.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
23
+ oafuncs-0.0.79.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
24
+ oafuncs-0.0.79.dist-info/RECORD,,