AaryanPalve5 / SAP-Stock

2 stars 2 forks source link

Create separate methods for stock graph and news scraping #4

Open Myash21 opened 1 week ago

Myash21 commented 1 week ago

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

capybara-brain346 commented 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

Myash21 commented 1 week ago

Yeah I guess so