优化代码
This commit is contained in:
@@ -29,6 +29,7 @@ CREATE TABLE image_hashes (
|
|||||||
```
|
```
|
||||||
查询脚本:查询两个qq号之间不连续的地址,找出漏上传的QQ号
|
查询脚本:查询两个qq号之间不连续的地址,找出漏上传的QQ号
|
||||||
```mysql
|
```mysql
|
||||||
|
USE qqinfo;
|
||||||
SELECT t1.id, t1.next_id
|
SELECT t1.id, t1.next_id
|
||||||
FROM (
|
FROM (
|
||||||
SELECT id, LEAD(id) OVER (ORDER BY id) AS next_id
|
SELECT id, LEAD(id) OVER (ORDER BY id) AS next_id
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
import pymysql, threading, time
|
import pymysql, threading, time
|
||||||
from queue import Queue
|
from queue import Queue
|
||||||
|
|
||||||
import requests
|
|
||||||
|
|
||||||
from concurrent.futures import ThreadPoolExecutor
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
from Tools import config, Hash, Image, imagehash, os, logging, download_image, remove_image, clean_image, compare
|
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)
|
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
|
retries = 0
|
||||||
while retries < max_retries:
|
while retries < max_retries:
|
||||||
|
|||||||
2
Tools.py
2
Tools.py
@@ -119,7 +119,7 @@ def download_image(_qqnumber):
|
|||||||
# 创建一个会进行重试的适配器
|
# 创建一个会进行重试的适配器
|
||||||
session = requests.Session()
|
session = requests.Session()
|
||||||
retry = Retry(
|
retry = Retry(
|
||||||
total=5, # 最多重试3次
|
total=255, # 最多重试255次
|
||||||
backoff_factor=1, # 每次重试的等待时间增加
|
backoff_factor=1, # 每次重试的等待时间增加
|
||||||
status_forcelist=[500, 502, 503, 504], # 针对这些HTTP状态码才重试
|
status_forcelist=[500, 502, 503, 504], # 针对这些HTTP状态码才重试
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ database = qqinfo
|
|||||||
table_name = image_hashes
|
table_name = image_hashes
|
||||||
id_column_name = id
|
id_column_name = id
|
||||||
hash_column_name = hash
|
hash_column_name = hash
|
||||||
pool_size = 100
|
pool_size = 2000
|
||||||
|
|
||||||
[logging]
|
[logging]
|
||||||
level = 20
|
level = 20
|
||||||
|
|||||||
28
main.py
28
main.py
@@ -1,30 +1,32 @@
|
|||||||
from time import sleep
|
|
||||||
from Thread import UploadThread, FindThread, ByNetFindThread, MySQLConnectionPool
|
from Thread import UploadThread, FindThread, ByNetFindThread, MySQLConnectionPool
|
||||||
from Tools import imagehash, Image, os, config
|
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 __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()
|
pool = MySQLConnectionPool()
|
||||||
Thread = FindThread(TargetImageHash, pool)
|
Thread = FindThread(TargetImageHash, pool)
|
||||||
Thread.start()
|
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]:
|
while baseArr <= TargetRange[1]:
|
||||||
Thread = ByNetFindThread(TargetImageHash, baseArr)
|
Thread = ByNetFindThread(TargetImageHash, baseArr)
|
||||||
Thread.start()
|
Thread.start()
|
||||||
baseArr += 1
|
baseArr += 1
|
||||||
|
|
||||||
elif type == 3:
|
elif mytype == 3:
|
||||||
pool = MySQLConnectionPool()
|
pool = MySQLConnectionPool()
|
||||||
while baseArr <= TargetRange[1]:
|
while baseArr <= TargetRange[1]:
|
||||||
Thread = UploadThread(baseArr, pool)
|
Thread = UploadThread(baseArr, pool)
|
||||||
|
|||||||
Reference in New Issue
Block a user