|
1 | 1 | from datetime import datetime |
| 2 | +import time |
2 | 3 |
|
3 | 4 | import yfinance as yf |
4 | 5 | from sqlalchemy.orm import Session |
5 | 6 |
|
6 | 7 | from classes.Asset import Asset, DB_Stock, AssetFastInfo, StockResponse |
7 | 8 | from models.models import Stock, AssetStatus |
8 | | -from services.email_service.email_service import send_email_notification |
9 | 9 | from services.risk_analysis.analyser import RiskAnalysis |
10 | 10 | from services.utils import calculate_shallow_risk_score |
11 | 11 |
|
@@ -39,20 +39,20 @@ def create_stock(db: Session, symbol: str) -> Stock: |
39 | 39 | status=AssetStatus.PENDING, |
40 | 40 | ) |
41 | 41 |
|
42 | | -# # Send email notification |
43 | | -# company_name = stock.asset_name |
44 | | -# email_subject = f"New Stock Added: {symbol}" |
45 | | -# email_message = f""" |
46 | | -# A new stock has been added to the database: |
| 42 | + # # Send email notification |
| 43 | + # company_name = stock.asset_name |
| 44 | + # email_subject = f"New Stock Added: {symbol}" |
| 45 | + # email_message = f""" |
| 46 | + # A new stock has been added to the database: |
47 | 47 |
|
48 | | -# Ticker: {symbol} |
49 | | -# Name: {company_name} |
50 | | -# Exchange: {stock.exchange} |
| 48 | + # Ticker: {symbol} |
| 49 | + # Name: {company_name} |
| 50 | + # Exchange: {stock.exchange} |
51 | 51 |
|
52 | | -# Initiate the model training process for this stock. |
53 | | -# Change the status to 'ACTIVE' when ready. |
54 | | -# """ |
55 | | -# send_email_notification(email_subject, email_message) |
| 52 | + # Initiate the model training process for this stock. |
| 53 | + # Change the status to 'ACTIVE' when ready. |
| 54 | + # """ |
| 55 | + # send_email_notification(email_subject, email_message) |
56 | 56 |
|
57 | 57 | db.add(stock) |
58 | 58 | db.commit() |
@@ -99,8 +99,11 @@ def update_all_stock_risk_scores(db: Session) -> None: |
99 | 99 | for stock in stocks: |
100 | 100 | try: |
101 | 101 | # Get risk score using the analyzer and update it |
| 102 | + print(f"Updating risk score for {stock.ticker_symbol}...") |
102 | 103 | analyser = RiskAnalysis(ticker=str(stock.ticker_symbol), db=db, db_stock=stock) |
103 | | - analyser.get_risk_score_and_update() |
| 104 | + analyser.calculate_overall_risk() |
| 105 | + print(f"Risk score for {stock.ticker_symbol} updated to {stock.risk_score}") |
| 106 | + time.sleep(30) # Pause for 30 seconds to respect API rate limits |
104 | 107 | except Exception as e: |
105 | 108 | # Log error but continue processing other stocks |
106 | 109 | print(f"Error updating risk score for {stock.ticker_symbol}: {str(e)}") |
|
0 commit comments