优化代码

This commit is contained in:
Qiea
2024-12-23 20:26:04 +08:00
parent 85b2b3723c
commit 1afa92ca4f
5 changed files with 19 additions and 19 deletions

View File

@@ -29,6 +29,7 @@ CREATE TABLE image_hashes (
```
查询脚本查询两个qq号之间不连续的地址找出漏上传的QQ号
```mysql
USE qqinfo;
SELECT t1.id, t1.next_id
FROM (
SELECT id, LEAD(id) OVER (ORDER BY id) AS next_id

View File

@@ -1,8 +1,5 @@
import pymysql, threading, time
from queue import Queue
import requests
from concurrent.futures import ThreadPoolExecutor
from Tools import config, Hash, Image, imagehash, os, logging, download_image, remove_image, clean_image, compare
@@ -27,7 +24,7 @@ class MySQLConnectionPool:
)
self.pool.put(conn)
def get_connection(self, max_retries=5, wait_time=1):
def get_connection(self, max_retries=65535, wait_time=3):
"""获取一个数据库连接,如果连接池为空,继续尝试直到能够获取连接"""
retries = 0
while retries < max_retries:

View File

@@ -119,7 +119,7 @@ def download_image(_qqnumber):
# 创建一个会进行重试的适配器
session = requests.Session()
retry = Retry(
total=5, # 最多重试3
total=255, # 最多重试255
backoff_factor=1, # 每次重试的等待时间增加
status_forcelist=[500, 502, 503, 504], # 针对这些HTTP状态码才重试
)

View File

@@ -11,7 +11,7 @@ database = qqinfo
table_name = image_hashes
id_column_name = id
hash_column_name = hash
pool_size = 100
pool_size = 2000
[logging]
level = 20

28
main.py
View File

@@ -1,30 +1,32 @@
from time import sleep
from Thread import UploadThread, FindThread, ByNetFindThread, MySQLConnectionPool
from Tools import imagehash, Image, os, config
type = int(config['settings']['type'])
TargetRange = list(map(int, config['settings']['TargetRange'].split(',')))
TargetImagePath = config['settings']['TargetImage']
TargetImage = Image.open(TargetImagePath)
TargetImageHash = bytes.fromhex(str(imagehash.average_hash(TargetImage)))
baseArr = TargetRange[0]
if not os.path.exists('img'):
os.makedirs('img')
if __name__ == '__main__':
if type == 1:
mytype = int(config['settings']['type'])
TargetRange = list(map(int, config['settings']['TargetRange'].split(',')))
baseArr = TargetRange[0]
if not os.path.exists('img'):
os.makedirs('img')
if mytype == 1:
TargetImagePath = config['settings']['TargetImage']
TargetImage = Image.open(TargetImagePath)
TargetImageHash = bytes.fromhex(str(imagehash.average_hash(TargetImage)))
pool = MySQLConnectionPool()
Thread = FindThread(TargetImageHash, pool)
Thread.start()
elif type == 2:
elif mytype == 2:
TargetImagePath = config['settings']['TargetImage']
TargetImage = Image.open(TargetImagePath)
TargetImageHash = bytes.fromhex(str(imagehash.average_hash(TargetImage)))
while baseArr <= TargetRange[1]:
Thread = ByNetFindThread(TargetImageHash, baseArr)
Thread.start()
baseArr += 1
elif type == 3:
elif mytype == 3:
pool = MySQLConnectionPool()
while baseArr <= TargetRange[1]:
Thread = UploadThread(baseArr, pool)