MMADS commited on
Commit
2f92304
Β·
1 Parent(s): 46439ca

replaced days to look back with year

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -75,15 +75,15 @@ class CVEDashboard:
75
  self.last_request_time = time.time()
76
 
77
  def fetch_cves(self,
78
- days_back: int = 7,
79
  keyword: Optional[str] = None,
80
  severity: Optional[str] = None,
81
  results_per_page: int = 50) -> Tuple[List[Dict], str]:
82
  """
83
- Fetch CVEs from NVD API.
84
 
85
  Args:
86
- days_back: Number of days to look back
87
  keyword: Optional keyword to search
88
  severity: Optional severity filter (LOW, MEDIUM, HIGH, CRITICAL)
89
  results_per_page: Number of results per page (max 2000)
@@ -94,8 +94,8 @@ class CVEDashboard:
94
  try:
95
  self._rate_limit()
96
 
97
- end_date = datetime.now()
98
- start_date = end_date - timedelta(days=days_back)
99
 
100
  params = {
101
  'pubStartDate': start_date.strftime('%Y-%m-%dT00:00:00.000'),
@@ -125,7 +125,7 @@ class CVEDashboard:
125
  continue
126
  processed_cves.append(cve)
127
 
128
- status = f"βœ“ Fetched {len(processed_cves)} CVEs from the last {days_back} days"
129
  if keyword:
130
  status += f" matching '{keyword}'"
131
  if severity:
@@ -137,7 +137,7 @@ class CVEDashboard:
137
  return [], f"βœ— API Error: {str(e)}"
138
  except Exception as e:
139
  return [], f"βœ— Error: {str(e)}"
140
-
141
  def _process_cve(self, cve_data: Dict) -> Dict:
142
  """Process raw CVE data into a structured format."""
143
  cve_id = cve_data.get('id', 'Unknown')
@@ -518,12 +518,11 @@ def create_interface():
518
 
519
  gr.Markdown("### πŸ” Search Parameters")
520
 
521
- days_back = gr.Slider(
522
- minimum=1,
523
- maximum=30,
524
- value=7,
525
- step=1,
526
- label="Days to Look Back"
527
  )
528
 
529
  keyword = gr.Textbox(
@@ -654,10 +653,10 @@ def create_interface():
654
  )
655
 
656
  # Event handlers
657
- def fetch_and_display(days, keyword_search, severity):
658
  """Fetch CVEs and update all displays."""
659
  cves, status = dashboard.fetch_cves(
660
- days_back=days,
661
  keyword=keyword_search if keyword_search else None,
662
  severity=severity if severity else None
663
  )
@@ -750,7 +749,7 @@ def create_interface():
750
  # Wire up the event handlers
751
  fetch_btn.click(
752
  fn=fetch_and_display,
753
- inputs=[days_back, keyword, severity_filter],
754
  outputs=[cve_state, status_text, cve_table, severity_chart, timeline_chart, score_chart, cve_selector]
755
  )
756
 
@@ -787,7 +786,7 @@ def create_interface():
787
  # Load initial data
788
  interface.load(
789
  fn=fetch_and_display,
790
- inputs=[days_back, keyword, severity_filter],
791
  outputs=[cve_state, status_text, cve_table, severity_chart, timeline_chart, score_chart, cve_selector]
792
  )
793
 
 
75
  self.last_request_time = time.time()
76
 
77
  def fetch_cves(self,
78
+ year: int,
79
  keyword: Optional[str] = None,
80
  severity: Optional[str] = None,
81
  results_per_page: int = 50) -> Tuple[List[Dict], str]:
82
  """
83
+ Fetch CVEs from NVD API for a specific year.
84
 
85
  Args:
86
+ year: The year to fetch CVEs for.
87
  keyword: Optional keyword to search
88
  severity: Optional severity filter (LOW, MEDIUM, HIGH, CRITICAL)
89
  results_per_page: Number of results per page (max 2000)
 
94
  try:
95
  self._rate_limit()
96
 
97
+ start_date = datetime(year, 1, 1)
98
+ end_date = datetime(year, 12, 31)
99
 
100
  params = {
101
  'pubStartDate': start_date.strftime('%Y-%m-%dT00:00:00.000'),
 
125
  continue
126
  processed_cves.append(cve)
127
 
128
+ status = f"βœ“ Fetched {len(processed_cves)} CVEs from the year {year}"
129
  if keyword:
130
  status += f" matching '{keyword}'"
131
  if severity:
 
137
  return [], f"βœ— API Error: {str(e)}"
138
  except Exception as e:
139
  return [], f"βœ— Error: {str(e)}"
140
+
141
  def _process_cve(self, cve_data: Dict) -> Dict:
142
  """Process raw CVE data into a structured format."""
143
  cve_id = cve_data.get('id', 'Unknown')
 
518
 
519
  gr.Markdown("### πŸ” Search Parameters")
520
 
521
+ current_year = datetime.now().year
522
+ year_filter = gr.Dropdown(
523
+ choices=list(range(current_year, current_year - 10, -1)),
524
+ value=current_year,
525
+ label="Year"
 
526
  )
527
 
528
  keyword = gr.Textbox(
 
653
  )
654
 
655
  # Event handlers
656
+ def fetch_and_display(year, keyword_search, severity):
657
  """Fetch CVEs and update all displays."""
658
  cves, status = dashboard.fetch_cves(
659
+ year=year,
660
  keyword=keyword_search if keyword_search else None,
661
  severity=severity if severity else None
662
  )
 
749
  # Wire up the event handlers
750
  fetch_btn.click(
751
  fn=fetch_and_display,
752
+ inputs=[year_filter, keyword, severity_filter],
753
  outputs=[cve_state, status_text, cve_table, severity_chart, timeline_chart, score_chart, cve_selector]
754
  )
755
 
 
786
  # Load initial data
787
  interface.load(
788
  fn=fetch_and_display,
789
+ inputs=[year_filter, keyword, severity_filter],
790
  outputs=[cve_state, status_text, cve_table, severity_chart, timeline_chart, score_chart, cve_selector]
791
  )
792