refresh the page in a simple way after x time

main
vitrinekast 8 months ago
parent 754fb91de3
commit c4b075fe51

@ -29,6 +29,7 @@
<header>
<h1>TL;DR</h1>
<h2>too log didn't read</h2>
<p>This log was generated on 2024-03-18 16:00:25.550452, the next will be available after 2024-03-18 19:00:25.550452</p>
</header>
<nav class="slider slider--top">
<label for="time">time</label>
@ -330,6 +331,24 @@ colord:x:130:
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
window.addEventListener("DOMContentLoaded", function() {
var nextDate = new Date("2024-03-18 19:00:25.550452");
var now = new Date();
var ms = nextDate - now;
console.log("start a timeout in , ", ms);
if(ms > 0) {
window.setTimeout(function() {
// TODO: add a check if there is still an internet connection
// TODO: add a check if there is actually new content?
// TODO: think about server time vs. client time
window.location.reload(true);
}, ms + 10000);
}
});
</script>
</body>
</html>

@ -1,8 +1,9 @@
from jinja2 import Environment, FileSystemLoader
import subprocess
from datetime import datetime
from datetime import datetime, timedelta
today = datetime.today()
now = datetime.today()
next_report = now + timedelta(hours=3)
last_user_added = subprocess.run(["sudo", "journalctl","_COMM=useradd","-r","-n", "1" , "--output-fields=MESSAGE"], capture_output=True).stdout.decode('UTF-8')
users_created_today = subprocess.run(["sudo", "journalctl", "-S","today","_COMM=useradd","-r","-n","1","--output-fields=MESSAGE"], capture_output=True).stdout.decode('UTF-8')
@ -10,7 +11,7 @@ list_active_services = subprocess.run(["sudo", "service", "--status-all"], captu
list_groups = subprocess.run(["getent","group"], capture_output=True).stdout.decode('UTF-8')
since_last_boot = subprocess.run(["uptime","-s"], capture_output=True).stdout.decode('UTF-8').strip()
slb_date = datetime.strptime(since_last_boot, "%Y-%m-%d %H:%M:%S")
time_since_last_boot = today - slb_date
time_since_last_boot = now - slb_date
list_package_installs = subprocess.run(["grep", 'install', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8')
list_package_upgrade = subprocess.run(["grep", 'upgrade', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8')
list_package_remove = subprocess.run(["grep", 'remove', "/var/log/dpkg.log"], capture_output=True).stdout.decode('UTF-8')
@ -28,6 +29,8 @@ template = env.get_template("template.jinja")
# rendering the template and storing the resultant text in variable output
output = template.render(
now = now,
next_report = next_report,
last_user_added=last_user_added,
users_created_today=users_created_today,
list_active_services=list_active_services,

@ -29,6 +29,7 @@
<header>
<h1>TL;DR</h1>
<h2>too log didn't read</h2>
<p>This log was generated on {{ now }}, the next will be available after {{ next_report }}</p>
</header>
<nav class="slider slider--top">
<label for="time">time</label>
@ -171,6 +172,24 @@
<script type="text/javascript" src="script.js"></script>
<script type="text/javascript">
window.addEventListener("DOMContentLoaded", function() {
var nextDate = new Date("{{ next_report }}");
var now = new Date();
var ms = nextDate - now;
console.log("start a timeout in , ", ms);
if(ms > 0) {
window.setTimeout(function() {
// TODO: add a check if there is still an internet connection
// TODO: add a check if there is actually new content?
// TODO: think about server time vs. client time
window.location.reload(true);
}, ms + 10000);
}
});
</script>
</body>
</html>
Loading…
Cancel
Save