cpatino10 commited on
Commit
e71d7d4
·
verified ·
1 Parent(s): 4b32e73

added logic to compare start date to today's date

Browse files
Files changed (1) hide show
  1. app.py +9 -3
app.py CHANGED
@@ -1,5 +1,5 @@
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
- import datetime
3
  import requests
4
  import pandas as pd
5
  import pytz
@@ -27,8 +27,14 @@ def fetch_historical_price_data(symbol: str, start_date: str) -> list[dict]:
27
  if not FMP_KEY:
28
  return [{"error": "Missing FMP_KEY environment variable"}]
29
 
30
- #Get today's date to validate start_date input
31
- today = datetime.now()
 
 
 
 
 
 
32
 
33
  url = f"https://financialmodelingprep.com/stable/historical-price-eod/non-split-adjusted?symbol={symbol}&from={start_date}&apikey={FMP_API_KEY}"
34
 
 
1
  from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
+ from datetime import datetime, date
3
  import requests
4
  import pandas as pd
5
  import pytz
 
27
  if not FMP_KEY:
28
  return [{"error": "Missing FMP_KEY environment variable"}]
29
 
30
+ today = datetime.now().date()
31
+ try:
32
+ start_dt = datetime.strptime(start_date, "%Y-%m-%d").date()
33
+ except ValueError:
34
+ return [{"error": "Invalid date format. Use 'YYYY-MM-DD'."}]
35
+
36
+ if start_dt > today:
37
+ return [{"error": f"The start date '{start_date}' is in the future (after today {today})."}]
38
 
39
  url = f"https://financialmodelingprep.com/stable/historical-price-eod/non-split-adjusted?symbol={symbol}&from={start_date}&apikey={FMP_API_KEY}"
40