'.'
This commit is contained in:
283
fix_update_thread.py
Normal file
283
fix_update_thread.py
Normal file
@@ -0,0 +1,283 @@
|
||||
with open('G:\\PyCode\\domainScanDemo\\app\\ui\\domain_filter.py', 'r', encoding='utf-8') as f:
|
||||
content = f.read()
|
||||
|
||||
# 找到UpdateThread类
|
||||
start_idx = content.find('class UpdateThread(QThread):')
|
||||
if start_idx == -1:
|
||||
print('UpdateThread class not found')
|
||||
else:
|
||||
# 找到类的结束位置(下一个类的开始)
|
||||
end_idx = content.find('class QueryThread(QThread):', start_idx)
|
||||
if end_idx == -1:
|
||||
end_idx = len(content)
|
||||
|
||||
# 构建新的UpdateThread类
|
||||
new_update_thread = '''class UpdateThread(QThread):
|
||||
"""
|
||||
批量更新线程
|
||||
"""
|
||||
update_finished = Signal(int, dict)
|
||||
|
||||
def __init__(self, selected_domains, update_values):
|
||||
super().__init__()
|
||||
self.selected_domains = selected_domains
|
||||
self.update_values = update_values
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
执行批量更新
|
||||
"""
|
||||
# 转换状态值的映射
|
||||
status_mappings = {
|
||||
'复核状态': {
|
||||
'无需复核': 0,
|
||||
'待人工复核': 1,
|
||||
'人工通过': 2,
|
||||
'人工拒绝': 3
|
||||
},
|
||||
'备案历史': {
|
||||
'待检测': 1,
|
||||
'有备案记录': 2,
|
||||
'没有备案记录': 3
|
||||
},
|
||||
'备案年份': {
|
||||
'2026': 2026,
|
||||
'2025': 2025,
|
||||
'2024': 2024,
|
||||
'2023': 2023,
|
||||
'2022': 2022,
|
||||
'2021': 2021,
|
||||
'2020': 2020
|
||||
},
|
||||
'域名快照年份': {
|
||||
'2026,2025,2024': '2026,2025,2024',
|
||||
'2026': '2026',
|
||||
'2025': '2025',
|
||||
'2024': '2024',
|
||||
'2023': '2023',
|
||||
'2022': '2022',
|
||||
'2021': '2021',
|
||||
'2020': '2020'
|
||||
},
|
||||
'单位性质': {
|
||||
'企业': '企业',
|
||||
'个人': '个人'
|
||||
},
|
||||
'百度历史收录状态': {
|
||||
'是': True,
|
||||
'否': False
|
||||
},
|
||||
'百度site收录状态': {
|
||||
'是': True,
|
||||
'否': False
|
||||
},
|
||||
'title是否简体中文': {
|
||||
'是': True,
|
||||
'否': False
|
||||
},
|
||||
'360 site收录状态': {
|
||||
'是': True,
|
||||
'否': False
|
||||
},
|
||||
'Google site收录状态': {
|
||||
'是': True,
|
||||
'否': False
|
||||
},
|
||||
'快照历史友链数量是否大于10': {
|
||||
'是': True,
|
||||
'否': False
|
||||
}
|
||||
}
|
||||
|
||||
updated_count = 0
|
||||
update_data = {}
|
||||
|
||||
try:
|
||||
db = Database()
|
||||
# 获取一个数据库连接,在整个批量更新过程中使用
|
||||
conn, cur = db.connect()
|
||||
if not conn or not cur:
|
||||
logger.error("获取数据库连接失败")
|
||||
self.update_finished.emit(0, {})
|
||||
return
|
||||
|
||||
try:
|
||||
for domain in self.selected_domains:
|
||||
# 获取域名ID
|
||||
domain_info = db.get_domain_by_name(domain)
|
||||
if domain_info:
|
||||
try:
|
||||
domain_update_data = {}
|
||||
|
||||
# 1. 复核状态
|
||||
review_status_value = self.update_values['review_status']
|
||||
if review_status_value != '不更新':
|
||||
status_value = status_mappings['复核状态'][review_status_value]
|
||||
cur.execute("UPDATE domains SET review_status = %s WHERE id = %s", (status_value, domain_info['id']))
|
||||
domain_update_data['review_status'] = review_status_value
|
||||
|
||||
# 2. 域名过期时间
|
||||
expire_date_value = self.update_values['expire_date']
|
||||
if expire_date_value and expire_date_value != '不更新':
|
||||
if expire_date_value == '当前时间':
|
||||
cur.execute("UPDATE domains SET expire_date = CURRENT_TIMESTAMP WHERE id = %s", (domain_info['id'],))
|
||||
import datetime
|
||||
domain_update_data['expire_date'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
else:
|
||||
cur.execute("UPDATE domains SET expire_date = %s WHERE id = %s", (expire_date_value, domain_info['id']))
|
||||
domain_update_data['expire_date'] = expire_date_value
|
||||
|
||||
# 3. 备案历史
|
||||
has_beian_value = self.update_values['has_beian']
|
||||
if has_beian_value != '不更新':
|
||||
status_value = status_mappings['备案历史'][has_beian_value]
|
||||
cur.execute("UPDATE domains SET has_beian = %s WHERE id = %s", (status_value, domain_info['id']))
|
||||
domain_update_data['has_beian'] = has_beian_value
|
||||
|
||||
# 4. 备案年份
|
||||
beian_year_value = self.update_values['beian_year']
|
||||
if beian_year_value and beian_year_value != '不更新':
|
||||
cur.execute("UPDATE domains SET beian_year = %s WHERE id = %s", (beian_year_value, domain_info['id']))
|
||||
domain_update_data['beian_year'] = beian_year_value
|
||||
|
||||
# 5. 域名快照年份
|
||||
snapshot_years_value = self.update_values['snapshot_years']
|
||||
if snapshot_years_value and snapshot_years_value != '不更新':
|
||||
cur.execute("UPDATE domains SET snapshot_years = %s WHERE id = %s", (snapshot_years_value, domain_info['id']))
|
||||
domain_update_data['snapshot_years'] = snapshot_years_value
|
||||
|
||||
# 6. 单位性质
|
||||
company_type_value = self.update_values['company_type']
|
||||
if company_type_value != '不更新':
|
||||
status_value = status_mappings['单位性质'][company_type_value]
|
||||
cur.execute("UPDATE domains SET company_type = %s WHERE id = %s", (status_value, domain_info['id']))
|
||||
domain_update_data['company_type'] = company_type_value
|
||||
|
||||
# 7. 检测时间
|
||||
detect_time_value = self.update_values['detect_time']
|
||||
if detect_time_value and detect_time_value != '不更新':
|
||||
if detect_time_value == '当前时间':
|
||||
cur.execute("UPDATE domains SET detect_time = CURRENT_TIMESTAMP WHERE id = %s", (domain_info['id'],))
|
||||
import datetime
|
||||
domain_update_data['detect_time'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
else:
|
||||
cur.execute("UPDATE domains SET detect_time = %s WHERE id = %s", (detect_time_value, domain_info['id']))
|
||||
domain_update_data['detect_time'] = detect_time_value
|
||||
|
||||
# 8. 检查domain_detections表中是否存在记录
|
||||
cur.execute("SELECT id FROM domain_detections WHERE domain_id = %s", (domain_info['id'],))
|
||||
detection_id = cur.fetchone()
|
||||
|
||||
# 9. 首页网址
|
||||
website_url_value = self.update_values['website_url']
|
||||
if website_url_value != '不更新':
|
||||
# 更新域名表中的website_url字段
|
||||
cur.execute("UPDATE domains SET website_url = %s WHERE id = %s", (website_url_value, domain_info['id']))
|
||||
domain_update_data['website_url'] = website_url_value
|
||||
|
||||
# 10. 百度历史收录状态
|
||||
baidu_history_value = self.update_values['baidu_history']
|
||||
if baidu_history_value != '不更新':
|
||||
status_value = status_mappings['百度历史收录状态'][baidu_history_value]
|
||||
# 转换为JSON格式
|
||||
import json
|
||||
json_value = json.dumps({"status": status_value})
|
||||
if detection_id:
|
||||
cur.execute("UPDATE domain_detections SET baidu_history = %s WHERE domain_id = %s", (json_value, domain_info['id']))
|
||||
else:
|
||||
cur.execute("INSERT INTO domain_detections (domain_id, baidu_history) VALUES (%s, %s)", (domain_info['id'], json_value))
|
||||
domain_update_data['baidu_history'] = baidu_history_value
|
||||
|
||||
# 11. 百度site收录状态
|
||||
baidu_site_value = self.update_values['baidu_site']
|
||||
if baidu_site_value != '不更新':
|
||||
status_value = status_mappings['百度site收录状态'][baidu_site_value]
|
||||
# 转换为JSON格式
|
||||
import json
|
||||
json_value = json.dumps({"status": status_value})
|
||||
if detection_id:
|
||||
cur.execute("UPDATE domain_detections SET baidu_site = %s WHERE domain_id = %s", (json_value, domain_info['id']))
|
||||
else:
|
||||
cur.execute("INSERT INTO domain_detections (domain_id, baidu_site) VALUES (%s, %s)", (domain_info['id'], json_value))
|
||||
domain_update_data['baidu_site'] = baidu_site_value
|
||||
|
||||
# 12. title是否简体中文
|
||||
is_chinese_title_value = self.update_values['is_chinese_title']
|
||||
if is_chinese_title_value != '不更新':
|
||||
status_value = status_mappings['title是否简体中文'][is_chinese_title_value]
|
||||
if detection_id:
|
||||
cur.execute("UPDATE domain_detections SET is_chinese_title = %s WHERE domain_id = %s", (status_value, domain_info['id']))
|
||||
else:
|
||||
cur.execute("INSERT INTO domain_detections (domain_id, is_chinese_title) VALUES (%s, %s)", (domain_info['id'], status_value))
|
||||
domain_update_data['is_chinese_title'] = is_chinese_title_value
|
||||
|
||||
# 13. 360 site收录状态
|
||||
qihu360_site_value = self.update_values['qihu360_site']
|
||||
if qihu360_site_value != '不更新':
|
||||
status_value = status_mappings['360 site收录状态'][qihu360_site_value]
|
||||
# 转换为JSON格式
|
||||
import json
|
||||
json_value = json.dumps({"status": status_value})
|
||||
if detection_id:
|
||||
cur.execute("UPDATE domain_detections SET qihu360_site = %s WHERE domain_id = %s", (json_value, domain_info['id']))
|
||||
else:
|
||||
cur.execute("INSERT INTO domain_detections (domain_id, qihu360_site) VALUES (%s, %s)", (domain_info['id'], json_value))
|
||||
domain_update_data['qihu360_site'] = qihu360_site_value
|
||||
|
||||
# 14. Google site收录状态
|
||||
google_site_value = self.update_values['google_site']
|
||||
if google_site_value != '不更新':
|
||||
status_value = status_mappings['Google site收录状态'][google_site_value]
|
||||
# 转换为JSON格式
|
||||
import json
|
||||
json_value = json.dumps({"status": status_value})
|
||||
if detection_id:
|
||||
cur.execute("UPDATE domain_detections SET google_site = %s WHERE domain_id = %s", (json_value, domain_info['id']))
|
||||
else:
|
||||
cur.execute("INSERT INTO domain_detections (domain_id, google_site) VALUES (%s, %s)", (domain_info['id'], json_value))
|
||||
domain_update_data['google_site'] = google_site_value
|
||||
|
||||
# 15. 友链数量
|
||||
backlink_count_value = self.update_values['backlink_count']
|
||||
if backlink_count_value and backlink_count_value != '不更新':
|
||||
# 更新domains表中的backlink_count字段
|
||||
cur.execute("UPDATE domains SET backlink_count = %s WHERE id = %s", (backlink_count_value, domain_info['id']))
|
||||
# 同时更新domain_detections表中的backlink_count_gt_10字段(是否大于10)
|
||||
backlink_count_gt_10 = int(backlink_count_value) > 10
|
||||
if detection_id:
|
||||
cur.execute("UPDATE domain_detections SET backlink_count_gt_10 = %s WHERE domain_id = %s", (backlink_count_gt_10, domain_info['id']))
|
||||
else:
|
||||
cur.execute("INSERT INTO domain_detections (domain_id, backlink_count_gt_10) VALUES (%s, %s)", (domain_info['id'], backlink_count_gt_10))
|
||||
domain_update_data['backlink_count'] = backlink_count_value
|
||||
|
||||
# 提交事务
|
||||
conn.commit()
|
||||
updated_count += 1
|
||||
update_data[domain] = domain_update_data
|
||||
except Exception as e:
|
||||
logger.error(f"更新域名状态失败: {e}")
|
||||
if conn:
|
||||
try:
|
||||
conn.rollback()
|
||||
except:
|
||||
pass
|
||||
except Exception as e:
|
||||
logger.error(f"批量更新失败: {e}")
|
||||
finally:
|
||||
# 关闭连接
|
||||
db.close(conn, cur)
|
||||
except Exception as e:
|
||||
logger.error(f"更新状态失败: {e}")
|
||||
|
||||
# 发送更新完成信号
|
||||
self.update_finished.emit(updated_count, update_data)
|
||||
'''
|
||||
|
||||
# 替换UpdateThread类
|
||||
new_content = content[:start_idx] + new_update_thread + content[end_idx:]
|
||||
|
||||
# 写回文件
|
||||
with open('G:\\PyCode\\domainScanDemo\\app\\ui\\domain_filter.py', 'w', encoding='utf-8') as f:
|
||||
f.write(new_content)
|
||||
|
||||
print('UpdateThread class updated successfully')
|
||||
Reference in New Issue
Block a user