Open Myash21 opened 1 week ago
@app.route("/stock_data/<symbol>")
def stock_data(symbol):
# Attempt to delete the Chroma database with retry logic
retries = 5
for attempt in range(retries):
try:
delete_chroma_collection() # Attempt to delete the collection
break # Exit loop if successful
except Exception as e:
print(f"Attempt {attempt + 1}: {e}")
time.sleep(1) # Wait before retrying
# Fetch stock data
stock = yf.Ticker(symbol)
data = stock.history(period="1mo")
if data.empty:
return jsonify({"error": "No data found for the symbol provided."})
prices = data["Close"].to_dict()
labels = list(prices.keys())
values = list(prices.values())
# Run the news scraper
NewsScrapper(site="https://finviz.com/quote.ashx?t=", ticker=symbol).run_scrapper()
return jsonify({"labels": labels, "values": values})
we probably need to move the NewsScrapper entirely to a separate method
Yeah I guess so
Create Separate methods for stock graph and news scraping
Inside app.py "/stock_data/" route
divide the two operations into separate methods to reduce the time for required for displaying stock history graph
Check lines 87 and 97