MMADS commited on
Commit
9c17941
·
1 Parent(s): f2c2857

keep fixing the year issue in API

Browse files
Files changed (1) hide show
  1. app.py +15 -6
app.py CHANGED
@@ -80,7 +80,8 @@ class CVEDashboard:
80
  severity: Optional[str] = None,
81
  results_per_page: int = 2000) -> Tuple[List[Dict], str]:
82
  """
83
- Fetch CVEs from NVD API for a specific year, handling the 120-day range limit.
 
84
 
85
  Args:
86
  year: The year to fetch CVEs for.
@@ -93,12 +94,20 @@ class CVEDashboard:
93
  """
94
  try:
95
  all_vulnerabilities = []
 
 
96
  year_start = datetime(year, 1, 1)
97
- year_end = datetime(year, 12, 31)
98
 
 
 
 
 
 
 
 
99
  current_start = year_start
100
 
101
- while current_start <= year_end:
102
  self._rate_limit()
103
 
104
  # Calculate the end of the chunk, respecting the 120-day limit
@@ -107,8 +116,8 @@ class CVEDashboard:
107
  logger.info(f"Fetching CVEs from {current_start.date()} to {chunk_end.date()}")
108
 
109
  params = {
110
- 'pubStartDate': current_start.strftime('%Y-%m-%dT00:00:00.000'),
111
- 'pubEndDate': chunk_end.strftime('%Y-%m-%dT23:59:59.999'),
112
  'resultsPerPage': min(results_per_page, 2000)
113
  }
114
 
@@ -532,7 +541,7 @@ def create_interface():
532
  )
533
  else:
534
  gr.Markdown("### ✅ AI Ready")
535
- gr.Markdown("HuggingFace token configured via environment variable")
536
  hf_token = gr.State(dashboard.hf_token) # Hidden state
537
 
538
  gr.Markdown("### 🔍 Search Parameters")
 
80
  severity: Optional[str] = None,
81
  results_per_page: int = 2000) -> Tuple[List[Dict], str]:
82
  """
83
+ Fetch CVEs from NVD API for a specific year, handling the 120-day range limit
84
+ and ensuring the date range does not extend into the future.
85
 
86
  Args:
87
  year: The year to fetch CVEs for.
 
94
  """
95
  try:
96
  all_vulnerabilities = []
97
+ now = datetime.now()
98
+
99
  year_start = datetime(year, 1, 1)
 
100
 
101
+ # If the selected year is the current year, end the search today.
102
+ # Otherwise, use the end of the selected year.
103
+ if year == now.year:
104
+ year_end = now
105
+ else:
106
+ year_end = datetime(year, 12, 31, 23, 59, 59)
107
+
108
  current_start = year_start
109
 
110
+ while current_start < year_end:
111
  self._rate_limit()
112
 
113
  # Calculate the end of the chunk, respecting the 120-day limit
 
116
  logger.info(f"Fetching CVEs from {current_start.date()} to {chunk_end.date()}")
117
 
118
  params = {
119
+ 'pubStartDate': current_start.strftime('%Y-%m-%dT%H:%M:%S.000'),
120
+ 'pubEndDate': chunk_end.strftime('%Y-%m-%dT%H:%M:%S.999'),
121
  'resultsPerPage': min(results_per_page, 2000)
122
  }
123
 
 
541
  )
542
  else:
543
  gr.Markdown("### ✅ AI Ready")
544
+ gr.Markdown("!!!This whole column will be rewritten!!")
545
  hf_token = gr.State(dashboard.hf_token) # Hidden state
546
 
547
  gr.Markdown("### 🔍 Search Parameters")