From e134ee26920be65dfe651a41429fef339463c93d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Sat, 14 Feb 2026 10:04:53 +0100 Subject: [PATCH] app --- cve_handler.py | 95 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/cve_handler.py b/cve_handler.py index 92a3c8e..a1d4dcf 100644 --- a/cve_handler.py +++ b/cve_handler.py @@ -505,30 +505,77 @@ class CVEHandler: logger.info(f"Total unique CVEs after deduplication: {len(unique_cves)}") + new_count = 0 + updated_count = 0 + with self.get_db_connection() as conn: cursor = conn.cursor() for cve_id, cve in unique_cves.items(): cursor.execute(""" - INSERT OR REPLACE INTO cve_cache - (cve_id, vendor_code, description, published_date, last_modified, - cvss_score, cvss_vector, severity, refs, cwe_ids, - affected_products, raw_data, updated_at) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, CURRENT_TIMESTAMP) - """, ( - cve_id, - vendor_code, - cve.get('description'), - cve.get('published_date'), - cve.get('last_modified'), - cve.get('cvss_score'), - cve.get('cvss_vector'), - cve.get('severity'), - cve.get('references'), - cve.get('cwe_ids'), - None, - cve.get('raw_data') - )) + SELECT discord_notified FROM cve_cache WHERE cve_id = ? + """, (cve_id,)) + + existing = cursor.fetchone() + + if not existing: + cursor.execute(""" + INSERT INTO cve_cache + (cve_id, vendor_code, description, published_date, last_modified, + cvss_score, cvss_vector, severity, refs, cwe_ids, + affected_products, raw_data, discord_notified, + created_at, updated_at) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP) + """, ( + cve_id, + vendor_code, + cve.get('description'), + cve.get('published_date'), + cve.get('last_modified'), + cve.get('cvss_score'), + cve.get('cvss_vector'), + cve.get('severity'), + cve.get('references'), + cve.get('cwe_ids'), + None, + cve.get('raw_data') + )) + new_count += 1 + else: + old_notified = existing[0] + + cursor.execute(""" + UPDATE cve_cache SET + vendor_code = ?, + description = ?, + published_date = ?, + last_modified = ?, + cvss_score = ?, + cvss_vector = ?, + severity = ?, + refs = ?, + cwe_ids = ?, + affected_products = ?, + raw_data = ?, + discord_notified = ?, + updated_at = CURRENT_TIMESTAMP + WHERE cve_id = ? + """, ( + vendor_code, + cve.get('description'), + cve.get('published_date'), + cve.get('last_modified'), + cve.get('cvss_score'), + cve.get('cvss_vector'), + cve.get('severity'), + cve.get('references'), + cve.get('cwe_ids'), + None, + cve.get('raw_data'), + old_notified, + cve_id + )) + updated_count += 1 cursor.execute(""" INSERT OR REPLACE INTO cve_metadata @@ -540,11 +587,16 @@ class CVEHandler: list(unique_cves.keys())[0] if unique_cves else None )) - logger.info(f"✓ Successfully updated {len(unique_cves)} CVEs for {vendor['name']}") + if new_count > 0: + logger.info(f"Added {new_count} new CVEs for {vendor['name']}") + if updated_count > 0: + logger.info(f"Updated {updated_count} existing CVEs for {vendor['name']}") + + logger.info(f"Successfully processed {len(unique_cves)} CVEs for {vendor['name']}") return True except Exception as e: - logger.error(f"✗ Error updating vendor cache for {vendor_code}: {e}", exc_info=True) + logger.error(f"Error updating vendor cache for {vendor_code}: {e}", exc_info=True) try: with self.get_db_connection() as conn: @@ -559,6 +611,7 @@ class CVEHandler: return False + def get_vendor_cves(self, vendor_code: str, limit: int = None, offset: int = 0, severity: str = None, year: int = None) -> List[Dict]: with self.get_db_connection() as conn: