From 90f6f6ce3ebc7d2ceb40ed5ef8ce0e27329a7a31 Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 28 Aug 2024 15:20:33 +0200 Subject: [PATCH] feat: auto-generate coingecko.json on first run Added logic to check for the existence of 'coingecko.json' and generate it by executing 'coingecko.php' if it doesn't exist. This ensures that the necessary data file is available on first run, preventing potential errors or missing data. --- index.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/index.php b/index.php index db08555..dc4856a 100644 --- a/index.php +++ b/index.php @@ -9,6 +9,12 @@ $currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parentUrl = dirname($currentUrl); // Get currency data from JSON +if (!file_exists('coingecko.json')) { + // Special case: First run. + exec('php coingecko.php'); + sleep(1); +} + $api_cg = json_decode(file_get_contents('coingecko.json'), true); // Configuration file