oafuncs 0.0.98.5__py3-none-any.whl → 0.0.98.7__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/hycom_3hourly.py +71 -42
- oafuncs/oa_down/hycom_3hourly_proxy.py +1230 -0
- oafuncs/oa_down/read_proxy.py +108 -0
- oafuncs/oa_draw.py +65 -0
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.7.dist-info}/METADATA +2 -1
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.7.dist-info}/RECORD +9 -7
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.7.dist-info}/WHEEL +1 -1
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.7.dist-info}/licenses/LICENSE.txt +0 -0
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.7.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,108 @@
|
|
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
|
+
import threading
|
17
|
+
from queue import Queue
|
18
|
+
import random
|
19
|
+
import requests
|
20
|
+
import os
|
21
|
+
|
22
|
+
|
23
|
+
# 从文件中读取代理列表
|
24
|
+
def read_proxies_from_file(filename):
|
25
|
+
try:
|
26
|
+
with open(filename, "r") as file:
|
27
|
+
proxies = [line.strip() for line in file if line.strip()]
|
28
|
+
return proxies
|
29
|
+
except FileNotFoundError:
|
30
|
+
print(f"未找到文件: {filename},请检查文件是否存在。")
|
31
|
+
return []
|
32
|
+
|
33
|
+
|
34
|
+
# 测试单个代理的可用性
|
35
|
+
def test_single_proxy(proxy, test_url, working_proxies_queue):
|
36
|
+
try:
|
37
|
+
response = requests.get(test_url, proxies={"http": proxy, "https": proxy}, timeout=5)
|
38
|
+
if response.status_code == 200:
|
39
|
+
# print(f"代理 {proxy} 可用,返回 IP: {response.json()['origin']}")
|
40
|
+
working_proxies_queue.put(proxy)
|
41
|
+
else:
|
42
|
+
# print(f"代理 {proxy} 不可用,状态码: {response.status_code}")
|
43
|
+
pass
|
44
|
+
except Exception as e: # noqa: F841
|
45
|
+
# print(f"代理 {proxy} 不可用,错误: {e}")
|
46
|
+
pass
|
47
|
+
|
48
|
+
|
49
|
+
# 测试代理的可用性(多线程)
|
50
|
+
def test_proxies(proxies, test_url):
|
51
|
+
working_proxies_queue = Queue()
|
52
|
+
threads = []
|
53
|
+
|
54
|
+
# 为每个代理创建一个线程
|
55
|
+
for proxy in proxies:
|
56
|
+
thread = threading.Thread(target=test_single_proxy, args=(proxy, test_url, working_proxies_queue))
|
57
|
+
threads.append(thread)
|
58
|
+
thread.start()
|
59
|
+
|
60
|
+
# 等待所有线程完成
|
61
|
+
for thread in threads:
|
62
|
+
thread.join()
|
63
|
+
|
64
|
+
# 从队列中取出所有可用代理
|
65
|
+
working_proxies = []
|
66
|
+
while not working_proxies_queue.empty():
|
67
|
+
working_proxies.append(working_proxies_queue.get())
|
68
|
+
|
69
|
+
return working_proxies
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
# 主函数
|
75
|
+
def read_test(input_filename=r"E:\Code\Python\Tools\Yccol\output\http.txt"):
|
76
|
+
# 测试 URL
|
77
|
+
test_url = "http://httpbin.org/ip"
|
78
|
+
|
79
|
+
# 读取代理列表
|
80
|
+
proxies = read_proxies_from_file(input_filename)
|
81
|
+
if not proxies:
|
82
|
+
print(f"文件 '{input_filename}' 中没有找到有效的代理。")
|
83
|
+
return
|
84
|
+
|
85
|
+
# print(f"从文件 '{input_filename}' 中读取到 {len(proxies)} 个代理,开始测试...")
|
86
|
+
|
87
|
+
# 测试代理
|
88
|
+
working_proxies = test_proxies(proxies, test_url)
|
89
|
+
|
90
|
+
return working_proxies
|
91
|
+
|
92
|
+
def get_valid_proxy(input_filename=r"E:\Code\Python\Tools\Yccol\output\http.txt"):
|
93
|
+
working_proxies = read_test(input_filename)
|
94
|
+
if not working_proxies:
|
95
|
+
print("没有找到可用的代理。")
|
96
|
+
return None
|
97
|
+
choose_proxy = random.choice(working_proxies)
|
98
|
+
print(f"Randomly selected available proxy: {choose_proxy}")
|
99
|
+
|
100
|
+
# proxies = {"http": choose_proxy, "https": choose_proxy}
|
101
|
+
# return proxies
|
102
|
+
|
103
|
+
return choose_proxy
|
104
|
+
|
105
|
+
|
106
|
+
if __name__ == "__main__":
|
107
|
+
pwd = os.path.dirname(os.path.abspath(__file__))
|
108
|
+
read_test()
|
oafuncs/oa_draw.py
CHANGED
@@ -15,6 +15,7 @@ Python Version: 3.11
|
|
15
15
|
|
16
16
|
import warnings
|
17
17
|
|
18
|
+
import cv2
|
18
19
|
import cartopy.crs as ccrs
|
19
20
|
import cartopy.feature as cfeature
|
20
21
|
import matplotlib as mpl
|
@@ -132,6 +133,70 @@ def gif(image_paths: list[str], output_gif_name: str, frame_duration: float = 20
|
|
132
133
|
return
|
133
134
|
|
134
135
|
|
136
|
+
def movie(image_files, output_video_path, fps):
|
137
|
+
"""
|
138
|
+
从图像文件列表创建视频。
|
139
|
+
|
140
|
+
Args:
|
141
|
+
image_files (list): 按顺序排列的图像文件路径列表。
|
142
|
+
output_video_path (str): 输出视频文件的路径 (例如 'output.mp4')。
|
143
|
+
fps (int): 视频的帧率。
|
144
|
+
"""
|
145
|
+
if not image_files:
|
146
|
+
print("错误:图像文件列表为空。")
|
147
|
+
return
|
148
|
+
|
149
|
+
# 读取第一张图片以获取帧尺寸
|
150
|
+
try:
|
151
|
+
frame = cv2.imread(image_files[0])
|
152
|
+
if frame is None:
|
153
|
+
print(f"错误:无法读取第一张图片:{image_files[0]}")
|
154
|
+
return
|
155
|
+
height, width, layers = frame.shape
|
156
|
+
size = (width, height)
|
157
|
+
print(f"视频尺寸设置为:{size}")
|
158
|
+
except Exception as e:
|
159
|
+
print(f"读取第一张图片时出错:{e}")
|
160
|
+
return
|
161
|
+
|
162
|
+
# 选择编解码器并创建VideoWriter对象
|
163
|
+
# 对于 .mp4 文件,常用 'mp4v' 或 'avc1'
|
164
|
+
# 对于 .avi 文件,常用 'XVID' 或 'MJPG'
|
165
|
+
fourcc = cv2.VideoWriter_fourcc(*"mp4v") # 或者尝试 'avc1', 'XVID' 等
|
166
|
+
out = cv2.VideoWriter(output_video_path, fourcc, fps, size)
|
167
|
+
|
168
|
+
if not out.isOpened():
|
169
|
+
print(f"错误:无法打开视频文件进行写入:{output_video_path}")
|
170
|
+
print("请检查编解码器 ('fourcc') 是否受支持以及路径是否有效。")
|
171
|
+
return
|
172
|
+
|
173
|
+
print(f"开始将图像写入视频:{output_video_path}...")
|
174
|
+
for i, filename in enumerate(image_files):
|
175
|
+
try:
|
176
|
+
frame = cv2.imread(filename)
|
177
|
+
if frame is None:
|
178
|
+
print(f"警告:跳过无法读取的图像:{filename}")
|
179
|
+
continue
|
180
|
+
# 确保帧尺寸与初始化时相同,如果需要可以调整大小
|
181
|
+
current_height, current_width, _ = frame.shape
|
182
|
+
if (current_width, current_height) != size:
|
183
|
+
print(f"警告:图像 {filename} 的尺寸 ({current_width}, {current_height}) 与初始尺寸 {size} 不同。将调整大小。")
|
184
|
+
frame = cv2.resize(frame, size)
|
185
|
+
|
186
|
+
out.write(frame)
|
187
|
+
# 打印进度(可选)
|
188
|
+
if (i + 1) % 50 == 0 or (i + 1) == len(image_files):
|
189
|
+
print(f"已处理 {i + 1}/{len(image_files)} 帧")
|
190
|
+
|
191
|
+
except Exception as e:
|
192
|
+
print(f"处理图像 {filename} 时出错:{e}")
|
193
|
+
continue # 跳过有问题的帧
|
194
|
+
|
195
|
+
# 释放资源
|
196
|
+
out.release()
|
197
|
+
print(f"视频创建成功:{output_video_path}")
|
198
|
+
|
199
|
+
|
135
200
|
def add_lonlat_unit(longitudes: list[float] = None, latitudes: list[float] = None, decimal_places: int = 2) -> tuple[list[str], list[str]] | list[str]:
|
136
201
|
"""Convert longitude and latitude values to formatted string labels.
|
137
202
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: oafuncs
|
3
|
-
Version: 0.0.98.
|
3
|
+
Version: 0.0.98.7
|
4
4
|
Summary: Oceanic and Atmospheric Functions
|
5
5
|
Home-page: https://github.com/Industry-Pays/OAFuncs
|
6
6
|
Author: Kun Liu
|
@@ -27,6 +27,7 @@ Requires-Dist: requests
|
|
27
27
|
Requires-Dist: bs4
|
28
28
|
Requires-Dist: httpx
|
29
29
|
Requires-Dist: matplotlib
|
30
|
+
Requires-Dist: opencv-python
|
30
31
|
Requires-Dist: netCDF4
|
31
32
|
Requires-Dist: xlrd
|
32
33
|
Requires-Dist: geopandas
|
@@ -2,7 +2,7 @@ oafuncs/__init__.py,sha256=T_-VtnWWllV3Q91twT5Yt2sUapeA051QbPNnBxmg9nw,1456
|
|
2
2
|
oafuncs/oa_cmap.py,sha256=DimWT4Bg7uE5Lx8hSw1REp7whpsR2pFRStAwk1cowEM,11494
|
3
3
|
oafuncs/oa_data.py,sha256=0AbQ8_7vf9ecZaui6hmUjubkWRJxs4TGcdhJaPdbmP8,10958
|
4
4
|
oafuncs/oa_date.py,sha256=KqU-bHtC74hYsf6VgiA3i2vI__q_toOVR-whFy4cYP8,5523
|
5
|
-
oafuncs/oa_draw.py,sha256=
|
5
|
+
oafuncs/oa_draw.py,sha256=Wj2QBgyIPpV_dxaDrH10jqj_puK9ZM9rd-si-3VrsrE,17631
|
6
6
|
oafuncs/oa_file.py,sha256=goF5iRXJFFCIKhIjlkCnYYt0EYlJb_4r8AeYNZ0-SOk,16209
|
7
7
|
oafuncs/oa_help.py,sha256=_4AZgRDq5Or0vauNvq5IDDHIBoBfdOQtzak-mG1wwAw,4537
|
8
8
|
oafuncs/oa_nc.py,sha256=L1gqXxg93kIDsMOa87M0o-53KVmdqCipnXeF9XfzfY8,10513
|
@@ -21,9 +21,11 @@ oafuncs/_script/plot_dataset.py,sha256=zkSEnO_-biyagorwWXPoihts_cwuvripzEt-l9bHJ
|
|
21
21
|
oafuncs/_script/replace_file_content.py,sha256=eCFZjnZcwyRvy6b4mmIfBna-kylSZTyJRfgXd6DdCjk,5982
|
22
22
|
oafuncs/oa_down/User_Agent-list.txt,sha256=pHaMlElMvZ8TG4vf4BqkZYKqe0JIGkr4kCN0lM1Y9FQ,514295
|
23
23
|
oafuncs/oa_down/__init__.py,sha256=kRX5eTUCbAiz3zTaQM1501paOYS_3fizDN4Pa0mtNUA,585
|
24
|
-
oafuncs/oa_down/hycom_3hourly.py,sha256=
|
24
|
+
oafuncs/oa_down/hycom_3hourly.py,sha256=wWV14-OB9_LMmjUiZr3YXWBdKKwAyGXNa3Up7fSiWwk,55553
|
25
|
+
oafuncs/oa_down/hycom_3hourly_proxy.py,sha256=1eaoJGI_m-7w4ZZ3n7NGxkZaeFdsm0d3U-hyw8RFNbc,54563
|
25
26
|
oafuncs/oa_down/idm.py,sha256=4z5IvgfTyIKEI1kOtqXZwN7Jnfjwp6qDBOIoVyOLp0I,1823
|
26
27
|
oafuncs/oa_down/literature.py,sha256=2bF9gSKQbzcci9LcKE81j8JEjIJwON7jbwQB3gDDA3E,11331
|
28
|
+
oafuncs/oa_down/read_proxy.py,sha256=f5YidVA2ISRFNm-pgRsb_Omj0dySevrhcVoH6Y125UU,3237
|
27
29
|
oafuncs/oa_down/test_ua.py,sha256=l8MCD6yU2W75zRPTDKUZTJhCWNF9lfk-MiSFqAqKH1M,1398
|
28
30
|
oafuncs/oa_down/user_agent.py,sha256=TsPcAxFmMTYAEHRFjurI1bQBJfDhcA70MdHoUPwQmks,785
|
29
31
|
oafuncs/oa_model/__init__.py,sha256=__ImltHkP1bSsIpsmKpDE8QwwA-2Z8K7mZUHGGcRdro,484
|
@@ -35,8 +37,8 @@ oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,5
|
|
35
37
|
oafuncs/oa_sign/meteorological.py,sha256=8091SHo2L8kl4dCFmmSH5NGVHDku5i5lSiLEG5DLnOQ,6489
|
36
38
|
oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
|
37
39
|
oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
|
38
|
-
oafuncs-0.0.98.
|
39
|
-
oafuncs-0.0.98.
|
40
|
-
oafuncs-0.0.98.
|
41
|
-
oafuncs-0.0.98.
|
42
|
-
oafuncs-0.0.98.
|
40
|
+
oafuncs-0.0.98.7.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
41
|
+
oafuncs-0.0.98.7.dist-info/METADATA,sha256=HotYRm4-mVHvJqg_pe71FgQpZ7mYKjd6WGr2PBbIeJY,4272
|
42
|
+
oafuncs-0.0.98.7.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
|
43
|
+
oafuncs-0.0.98.7.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
44
|
+
oafuncs-0.0.98.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|