update data from server

This commit is contained in:
Aliberk Sandıkçı 2024-01-07 12:47:16 +03:00
parent b32337603b
commit 18c2805768
Signed by: asandikci
GPG Key ID: 25C67A03B5666BC1
3 changed files with 36 additions and 15 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ build/*
*.tar.gz
*.zip
/vendor/
config.php

View File

@ -64,7 +64,6 @@
}
document.getElementById("tebriks").style.display = "none";
if (localStorage.getItem("win") != null && localStorage.getItem("win") === "winned") {
console.log(localStorage.getItem("win"));
document.getElementById("tebriks").style.display = "block";
document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
}
@ -76,14 +75,16 @@
} else {
latest_visit = localStorage.getItem("latest_visit");
if (isSameDay(new Date(latest_visit), date)) {
console.log("same day!");
console.debug("Kullanıcı Son Girişi İle Aynı Günde");
} else {
console.log("different day!");
console.debug("Kullanıcı Farklı Bir Günde Giriş Yaptı, Statlar Sıfırlanıyor");
localStorage.removeItem("guesses");
localStorage.removeItem("latest_guess");
localStorage.removeItem("win");
}
localStorage.setItem("latest_visit", date);
}
<?php include './src/server.php'; ?>
<?php include __DIR__ . '/src/server.php'; ?>
current_guess = "<?php
if ($_POST['mainInput'] != null) {
echo htmlspecialchars($_POST['mainInput']);
@ -92,7 +93,7 @@
flagSame = 0;
if (localStorage.getItem("latest_guess") != null) {
if (current_guess == localStorage.getItem("latest_guess")) {
console.warn("EN SON TAHMININIZ ILE ŞIMDIKI AYNI !!!")
console.warn("EN SON TAHMININIZ ILE ŞIMDIKI AYNI !!! (veya sayfayı yenilemiş/geri gelmiş de olabilirsiniz)")
flagSame = 1;
}
localStorage.setItem("latest_guess", current_guess);
@ -108,16 +109,17 @@
var gj = JSON.parse('{"Guesses":[], "Values":[]}'); // guess json
if (localStorage.getItem("guesses") != null) {
console.log("local storage get!");
console.debug("Local Storage Succesfully Get!");
gj = JSON.parse(localStorage.getItem("guesses"));
}
if (current_guess != "" && flagSame == 0) {
gj["Guesses"].push(current_guess);
console.warn(current_guess);
console.debug("Denenen Kişi: " + current_guess);
gj["Values"].push(<?php if ($_POST['mainInput'] != null) {
$inner_cg = htmlspecialchars($_POST['mainInput']);
echo "'" . json_encode(comparePerson(reversePerson($inner_cg)), JSON_UNESCAPED_UNICODE) . "'";
}
echo "'" . json_encode(comparePerson(reversePerson($inner_cg)), JSON_UNESCAPED_UNICODE) . "'"; ?>);
?>);
localStorage.setItem("guesses", JSON.stringify(gj));
}
@ -150,7 +152,7 @@
table.appendChild(tr);
indata = JSON.parse(gj["Values"][i]);
console.warn(indata);
// console.warn(indata);
for (const key in criterias) {
if (innerFlag) crit_num++;
const td = document.createElement("td");
@ -183,10 +185,10 @@
}
}
console.log(gj);
// console.log(gj);
if (crit_num == (true_num + 1)) // +1 isim_soyisim sayılmadığı için
{
console.warn(crit_num, true_num);
// console.warn(crit_num, true_num);
document.getElementById("tebriks").style.display = "block";
document.getElementById("tebriks").innerHTML = "Tebrikler, günün şanslı kişisini buldun!"
localStorage.setItem("win", "winned");
@ -217,7 +219,7 @@
// UPDATES
const updates = <?php echo json_encode(sendDataDate()) ?>;
document.getElementById("latest-data").innerHTML = updates[0];
console.log("günün kişisi güncellenme zamanı: " + updates[1]);
console.info("Günün Kişisi, Son Güncelleme Zamanı: " + updates[1]);
/// AUTOCOMPLETE ///

View File

@ -3,9 +3,11 @@
use Yosymfony\Toml\Toml;
include 'todays.php';
include '../config.php';
require __DIR__ . '/../vendor/autoload.php';
$parser = new Toml();
$dock_local_test = 1;
# Fetch remote data each 1 hour
function updateRemoteData()
@ -14,7 +16,16 @@ function updateRemoteData()
# GET FROM GIT WITH ACCESS TOKEN AND SAVE TO data.toml
# MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!!
global $DATAACCESS_TOKEN;
$string = file_get_contents("https://git.aliberksandikci.com.tr/api/v1/repos/ifl/YurdleBackend/raw/data.toml?access_token=" . $DATAACCESS_TOKEN);
if ($string === FALSE) {
echo "Could not read the file.";
} else {
$file = __DIR__ . "/../data.toml";
file_put_contents($file, $string, LOCK_EX);
}
# REVIEW MAKE SURE FILE IS CHMOD 600 AND NOT ACCESSIBLE FROM USERSIDE !!!
parseTOML(); # parse again after update
@ -186,8 +197,15 @@ function getAPersonStats($person)
function parseTOML()
{
global $parser;
$array = $parser::ParseFile("data.toml");
return $array;
global $dock_local_test;
if ($dock_local_test) {
$array = $parser::ParseFile("../data.toml");
return $array;
} else {
$array = $parser::ParseFile("data.toml");
return $array;
}
}
updateRemoteData();
comparePerson('aliberk_sandikci24');