Spaces:
Sleeping
Sleeping
| 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>") |