function fetch_stock_data() {
    $output = shell_exec('python3 fetch_stocks.py');
    if ($output === null) {
        error_log("Python script did not execute properly.");
        return false;
    }
    $data = json_decode($output, true);
    if (json_last_error() !== JSON_ERROR_NONE) {
        error_log("JSON decode error: " . json_last_error_msg());
        error_log("Python script output: " . $output);
        return false;
    }
    return $data;
}

function display_stock_screener() {
    $stocks = fetch_stock_data();

    if (!$stocks) {
        return "Error fetching stock data. Check the error log for details.";
    }

    // Build HTML output
    $output = "<h1>Top 15 Most Active Stocks Under $11 with Largest Gap</h1>";
    $output .= "<table border='1'>";
    $output .= "<tr><th>Symbol</th><th>Price</th><th>Volume</th><th>Gap</th></tr>";
    foreach ($stocks as $stock) {
        $output .= "<tr>";
        $output .= "<td>{$stock['symbol']}</td>";
        $output .= "<td>{$stock['price']}</td>";
        $output .= "<td>{$stock['volume']}</td>";
        $output .= "<td>{$stock['gap']}</td>";
        $output .= "</tr>";
    }
    $output .= "</table>";

    return $output;
}
/*
 * jQuery Nivo Slider v2.6
 * http://nivo.dev7studios.com
 *
 * Copyright 2011, Gilbert Pellegrom
 * Free to use and abuse under the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * 
 * March 2010
 */
 
 
/* The Nivo Slider styles */
.nivoSlider {
	position:relative;
}
.nivoSlider img {
	position:absolute;
	top:0px;
	left:0px;
}
/* If an image is wrapped in a link */
.nivoSlider a.nivo-imageLink {
	position:absolute;
	top:0px;
	left:0px;
	width:100%;
	height:100%;
	border:0;
	padding:0;
	margin:0;
	z-index:6;
	display:none;
}
/* The slices and boxes in the Slider */
.nivo-slice {
	display:block;
	position:absolute;
	z-index:5;
	height:100%;
}
.nivo-box {
	display:block;
	position:absolute;
	z-index:5;
}
/* Caption styles */
.nivo-caption {
	position:absolute;
	left:0px;
	bottom:0px;
	background:#000;
	color:#fff;
	opacity:0.8; /* Overridden by captionOpacity setting */
	width:100%;
	z-index:8;
}
.nivo-caption p {
	padding:5px;
	margin:0;
}
.nivo-caption a {
	display:inline !important;
}
.nivo-html-caption {
    display:none;
}
/* Direction nav styles (e.g. Next & Prev) */
.nivo-directionNav a {
	position:absolute;
	top:45%;
	z-index:9;
	cursor:pointer;
}
.nivo-prevNav {
	left:0px;
}
.nivo-nextNav {
	right:0px;
}
/* Control nav styles (e.g. 1,2,3...) */
.nivo-controlNav a {
	position:relative;
	z-index:9;
	cursor:pointer;
}
.nivo-controlNav a.active {
	font-weight:bold;
}.theme-default .nivoSlider {
	position: relative;
	background: #fff url(images/loading.gif) no-repeat 50% 50%;
    -webkit-box-shadow: 0px 1px 5px 0px #4a4a4a;
    -moz-box-shadow: 0px 1px 5px 0px #4a4a4a;
    box-shadow: 0px 1px 5px 0px #4a4a4a;
}
.theme-default .nivoSlider img {
	position: absolute;
	top: 0px;
	left: 0px;
	display: none;
}
.theme-default .nivoSlider a {
	border: 0;
	display: block;
}

.theme-default .nivo-controlNav {
	position: absolute;
	left: 50%;
	bottom: 