Skip to content

Commit

Permalink
进一步优化,添加空值处理
Browse files Browse the repository at this point in the history
  • Loading branch information
Areedd committed Jan 1, 2025
1 parent 5e5bd30 commit 543e26a
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,31 +38,39 @@ def analyze():
phish_category, pred_target, matched_domain, \
plotvis, siamese_conf, pred_boxes, \
logo_recog_time, logo_match_time = phishpedia_cls.test_orig_phishpedia(url, screenshot_path, None)


# 添加结果处理逻辑
result = {
"isPhishing": bool(phish_category),
"brand": pred_target if pred_target else "unknown",
"legitUrl": f"https://{matched_domain[0]}" if matched_domain else "unknown",
"confidence": float(siamese_conf) if siamese_conf is not None else 0.0
}

# 记录日志
today = datetime.now().strftime('%Y%m%d')
log_file_path = os.path.join(log_dir, f'{today}_results.txt')

try:
with open(log_file_path, "a+", encoding='ISO-8859-1') as f:
result_file_write(f, current_dir, url, phish_category, pred_target, matched_domain, siamese_conf,
logo_recog_time, logo_match_time)
result_file_write(f, current_dir, url, phish_category, pred_target,
matched_domain if matched_domain else ["unknown"],
siamese_conf if siamese_conf is not None else 0.0,
logo_recog_time, logo_match_time)
except UnicodeError:
with open(log_file_path, "a+", encoding='utf-8') as f:
result_file_write(f, current_dir, url, phish_category, pred_target, matched_domain, siamese_conf,
logo_recog_time, logo_match_time)
# 目前返回示例数据
result = {
"isPhishing": bool(phish_category),
"brand": pred_target,
"legitUrl": "https://" + matched_domain[0],
"confidence": float(siamese_conf)
}
result_file_write(f, current_dir, url, phish_category, pred_target,
matched_domain if matched_domain else ["unknown"],
siamese_conf if siamese_conf is not None else 0.0,
logo_recog_time, logo_match_time)

if os.path.exists(screenshot_path):
os.remove(screenshot_path)

return jsonify(result)

except Exception as e:
print(e)
print(f"Error in analyze: {str(e)}")
log_error_path = os.path.join(log_dir, 'log_error.txt')
with open(log_error_path, "a+", encoding='utf-8') as f:
f.write(f'{datetime.now().strftime("%Y-%m-%d %H:%M:%S")} - {str(e)}\n')
Expand Down

0 comments on commit 543e26a

Please sign in to comment.