Spaces:
Sleeping
Sleeping
File size: 1,337 Bytes
19949cf c81501d 19949cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | import os
import json
def search_cves(keyword):
"""Search analyzed CVEs by keyword"""
if not os.path.exists('data'):
return []
results = []
for filename in os.listdir('data'):
if filename.endswith('.json'):
filepath = os.path.join('data', filename)
with open(filepath, 'r', encoding='utf-8') as f:
data = json.load(f)
# Search in description and AI summary
cve = data['cve_data']['cve']
description = cve['descriptions'][0]['value'].lower()
ai_summary = (data.get('ai_summary', '') or '').lower()
if keyword.lower() in description or keyword.lower() in ai_summary:
results.append({
'cve_id': data['cve_id'],
'analyzed_at': data.get('analyzed_at', ''),
'description': cve['descriptions'][0]['value'][:100] + '...'
})
return results
if __name__ == "__main__":
import sys
if len(sys.argv) > 1:
keyword = sys.argv[1]
results = search_cves(keyword)
print(f"Search results for '{keyword}':")
for r in results:
print(f" • {r['cve_id']}: {r['description']}")
else:
print("Usage: python search.py <keyword>") |