From 3fd44eae120399e4d3eefdd409fbf28eb8f60308 Mon Sep 17 00:00:00 2001
From: Marco Malavolti <marco.malavolti@gmail.com>
Date: Thu, 16 Jul 2020 03:27:55 +0200
Subject: [PATCH] Simplified research of the last date

---
 api.py        |  2 +-
 web/index.php | 16 ++++------------
 2 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/api.py b/api.py
index 6608ae4..39e7f9b 100755
--- a/api.py
+++ b/api.py
@@ -94,7 +94,7 @@ class EccsResults(Resource):
            if (eccsDataTable):
               return ''
            else:
-              return jsonify(error='FileNotFound: ECCS2 script has not been executed on this day')
+              return jsonify(error='FileNotFound: ECCS2 script has not been executed on %s' % date)
 
        for line in lines:
           # Strip the line feed and carriage return characters
diff --git a/web/index.php b/web/index.php
index d7775b0..17db15d 100644
--- a/web/index.php
+++ b/web/index.php
@@ -6,18 +6,10 @@ $firstFile = $files[3]; // [0] = '.' ; [1] = '..' ; [2] = '.gitignore'
 $str2strip = array("eccs2_", ".log");
 $firstDate = str_replace($str2strip, "", $firstFile);
 
-$latest_ctime = 0;
-$latest_filename = '';
-$d = dir($directory);
-while (false !== ($entry = $d->read())) {
-$filepath = "{$directory}/{$entry}";
-//Check whether the entry is a file etc.:
-    if(is_file($filepath) && filectime($filepath) > $latest_ctime) {
-    $latest_ctime = filectime($filepath);
-    $latest_filename = $entry;
-    }//end if is file etc.
-}//end while going over files in excel_uploads dir.
-$lastDate = str_replace($str2strip, "", $latest_filename);
+$files = scandir($directory, SCANDIR_SORT_DESCENDING);
+$lastFile = $files[0];
+
+$lastDate = str_replace($str2strip, "", $lastFile);
 ?>
 
 <!DOCTYPE html>
-- 
GitLab