oafuncs 0.0.98.5__py3-none-any.whl → 0.0.98.6__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 +51 -33
- oafuncs/oa_down/hycom_3hourly_proxy.py +1230 -0
- oafuncs/oa_down/read_proxy.py +108 -0
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.6.dist-info}/METADATA +1 -1
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.6.dist-info}/RECORD +8 -6
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.6.dist-info}/WHEEL +0 -0
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.6.dist-info}/licenses/LICENSE.txt +0 -0
- {oafuncs-0.0.98.5.dist-info → oafuncs-0.0.98.6.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()
|
@@ -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=zU7eNFyg5oa-5MVrCeCVyZfoYHukY7MA0-DmvCj5yIk,54723
|
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.6.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
|
41
|
+
oafuncs-0.0.98.6.dist-info/METADATA,sha256=g6aPVBYo1PEpyW-4-0o1HgXZiNJZKGg1p3YEP2skSAY,4242
|
42
|
+
oafuncs-0.0.98.6.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
43
|
+
oafuncs-0.0.98.6.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
|
44
|
+
oafuncs-0.0.98.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|