Spaces:
Sleeping
Sleeping
Upload forecaster_cli.py
Browse files- forecaster_cli.py +11 -3
forecaster_cli.py
CHANGED
|
@@ -98,13 +98,14 @@ def fetch_live_features(ticker):
|
|
| 98 |
def get_market_cap_tier(ticker):
|
| 99 |
print(f"[{ticker}] Resolving market cap classification from NSE servers...")
|
| 100 |
try:
|
| 101 |
-
|
|
|
|
| 102 |
if ticker in large: return "Large"
|
| 103 |
|
| 104 |
-
mid = pd.read_csv(TIERS["Mid"])['Symbol'].tolist()
|
| 105 |
if ticker in mid: return "Mid"
|
| 106 |
|
| 107 |
-
small = pd.read_csv(TIERS["Small"])['Symbol'].tolist()
|
| 108 |
if ticker in small: return "Small"
|
| 109 |
|
| 110 |
except Exception as e:
|
|
@@ -265,6 +266,13 @@ def run_daemon():
|
|
| 265 |
# Format report and save to JSON
|
| 266 |
report = df[['Ticker', 'Decision', 'Confidence', 'Reasoning', 'Sales_Growth', 'ROE', 'Debt_to_Equity', 'OPM']]
|
| 267 |
report_dict = report.to_dict(orient='records')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
import json
|
| 269 |
with open("nifty50_predictions.json", "w") as f:
|
| 270 |
json.dump({"last_updated": datetime.datetime.now().isoformat(), "predictions": report_dict}, f, indent=4)
|
|
|
|
| 98 |
def get_market_cap_tier(ticker):
|
| 99 |
print(f"[{ticker}] Resolving market cap classification from NSE servers...")
|
| 100 |
try:
|
| 101 |
+
ua = {'User-Agent': 'Mozilla/5.0'}
|
| 102 |
+
large = pd.read_csv(TIERS["Large"], storage_options=ua)['Symbol'].tolist()
|
| 103 |
if ticker in large: return "Large"
|
| 104 |
|
| 105 |
+
mid = pd.read_csv(TIERS["Mid"], storage_options=ua)['Symbol'].tolist()
|
| 106 |
if ticker in mid: return "Mid"
|
| 107 |
|
| 108 |
+
small = pd.read_csv(TIERS["Small"], storage_options=ua)['Symbol'].tolist()
|
| 109 |
if ticker in small: return "Small"
|
| 110 |
|
| 111 |
except Exception as e:
|
|
|
|
| 266 |
# Format report and save to JSON
|
| 267 |
report = df[['Ticker', 'Decision', 'Confidence', 'Reasoning', 'Sales_Growth', 'ROE', 'Debt_to_Equity', 'OPM']]
|
| 268 |
report_dict = report.to_dict(orient='records')
|
| 269 |
+
|
| 270 |
+
import math
|
| 271 |
+
for item in report_dict:
|
| 272 |
+
for k, v in item.items():
|
| 273 |
+
if isinstance(v, float) and math.isnan(v):
|
| 274 |
+
item[k] = None
|
| 275 |
+
|
| 276 |
import json
|
| 277 |
with open("nifty50_predictions.json", "w") as f:
|
| 278 |
json.dump({"last_updated": datetime.datetime.now().isoformat(), "predictions": report_dict}, f, indent=4)
|