<commit_before><?php
header("Content-type:application/json");
date_default_timezone_set('UTC');

require_once("classes/factions.php");
require_once("classes/lpstore.php");
require_once("classes/lpexchange.php");

$alwaysRecache = false; // Set true for testing only.

$factions = new Factions();

// Recache LP Stores
foreach ($factions->get() as $index => $faction) {
  $lpStore = new LPStore($faction->corp->id);
  if (
    is_null($lpStore->get()) // No cache exists.
    || new DateTime($lpStore->get()->cachedUntil) < new DateTime() // Cache is old.
    || $alwaysRecache === true // We just don't care. 
  ) {
    if (
      !is_null($lpStore->getWorkingCache()) // There is a working cache
      && (
        strtotime($lpStore->getWorkingCache()->cachedStarted) 
        > date('c', strtotime('-15 minutes', time())) // It started in the last 15 minutes
      )
    ) {
        // Recache in process, exit. 
        echo ('{"done": false, "faction": "'.$faction->corp->id.'", "stage": "store"}');
        die();
      }
    else {
      $lpStore->updateCache();
    }
  }
}


// Recache LP Store Exchange Prices
foreach ($factions->get() as $index => $faction) {
  $lpExchange = new LPExchange($faction->corp->id);
  if (
    is_null($lpExchange->get()) // No cache exists.
    || new DateTime($lpExchange->get()->cachedUntil) < new DateTime() // Cache is old.
    || $alwaysRecache === true // We just don't care. 
  ) {
    if (
      !is_null($lpExchange->getWorkingCache()) // There is a working cache
      && (
        strtotime($lpExchange->getWorkingCache()->cachedStarted) 
        > date('c', strtotime('-15 minutes', time())) // It started in the last 15 minutes
      )
    ) {
        // Recache in process, exit.
        echo ('{"done": false, "faction": "'.$faction->corp->id.'", "stage": "exchange"}');
        die();
      }
    else {
      $lpExchange->updateCache();
    }
  }
}

echo ('{"done": true}');

<commit_msg>use strtotime<commit_after><?php
header("Content-type:application/json");
date_default_timezone_set('UTC');

require_once("classes/factions.php");
require_once("classes/lpstore.php");
require_once("classes/lpexchange.php");

$alwaysRecache = false; // Set true for testing only.

$factions = new Factions();

// Recache LP Stores
foreach ($factions->get() as $index => $faction) {
  $lpStore = new LPStore($faction->corp->id);
  if (
    is_null($lpStore->get()) // No cache exists.
    || new DateTime($lpStore->get()->cachedUntil) < new DateTime() // Cache is old.
    || $alwaysRecache === true // We just don't care. 
  ) {
    if (
      !is_null($lpStore->getWorkingCache()) // There is a working cache
      && (
        strtotime($lpStore->getWorkingCache()->cachedStarted) 
        > strtotime('-15 minutes', time()) // It started in the last 15 minutes
      )
    ) {
        // Recache in process, exit. 
        echo ('{"done": false, "faction": "'.$faction->corp->id.'", "stage": "store"}');
        die();
      }
    else {
      $lpStore->updateCache();
    }
  }
}


// Recache LP Store Exchange Prices
foreach ($factions->get() as $index => $faction) {
  $lpExchange = new LPExchange($faction->corp->id);
  if (
    is_null($lpExchange->get()) // No cache exists.
    || new DateTime($lpExchange->get()->cachedUntil) < new DateTime() // Cache is old.
    || $alwaysRecache === true // We just don't care. 
  ) {
    if (
      !is_null($lpExchange->getWorkingCache()) // There is a working cache
      && (
        strtotime($lpExchange->getWorkingCache()->cachedStarted) 
        > strtotime('-15 minutes', time()) // It started in the last 15 minutes
      )
    ) {
        // Recache in process, exit.
        echo ('{"done": false, "faction": "'.$faction->corp->id.'", "stage": "exchange"}');
        die();
      }
    else {
      $lpExchange->updateCache();
    }
  }
}

echo ('{"done": true}');


{'fraction_non_alphanumeric': 0.18863049095607234, 'fraction_numerical': 0.004134366925064599, 'mean_word_length': 2.8100393700787403, 'pattern_counts': {'":': 14, '<': 9, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '772037', 'n_tokens_mistral': 1278, 'n_tokens_neox': 1218, 'n_words': 289}