update time format to internet time

This commit is contained in:
Görkem 2026-01-29 12:07:58 -08:00
parent da83e1e956
commit 62e001a6b7
2 changed files with 38 additions and 4 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
guestbook/*
import/*

40
app.py
View File

@ -2,7 +2,8 @@ import os
import json
import time
import requests
from datetime import datetime
import math
from datetime import datetime, timezone, timedelta
from flask import Flask, request, jsonify
from flask_cors import CORS
@ -12,7 +13,11 @@ app = Flask(__name__)
DAILY_LIMIT = 50
DATA_DIR = 'guestbook'
currentDate = datetime.now().strftime('%Y-%m-%d')
#get current UTC time and convert it to BMT
now_utc = datetime.now(timezone.utc)
bmt = now_utc + timedelta(hours=1)
currentDate = bmt.strftime('%Y-%m-%d')
submissionCountDay = 0
@ -71,11 +76,14 @@ def addComment():
if not website.startswith(('http://', 'https://')):
website = 'https://' + website
date_str=time.strftime("%d-%m-%Y")
itime_beats=itime()
entry = {
'name': name,
'message': message,
'website': website,
'date': time.strftime("%d-%m-%Y %H:%M")
'date': f"{date_str} @{itime_beats:03d}"
}
now = datetime.now()
@ -103,6 +111,30 @@ def addComment():
return jsonify({"status": "success"})
#helper functions:
# Source - https://stackoverflow.com/a/51722192
# Posted by kernel
# Retrieved 2026-01-29, License - CC BY-SA 4.0
#thanks @kernel!
def itime():
"""Calculate and return Swatch Internet Time
:returns: No. of beats (Swatch Internet Time)
:rtype: float
"""
midnight = bmt.replace(hour=0, minute=0, second=0, microsecond=0)
seconds_passed = (bmt - midnight).total_seconds()
beats = int(math.floor(seconds_passed / 86.4))
# if beats > 1000:
# beats -= 1000
# elif beats < 0:
# beats += 1000
return beats
def send_ntfy_notification(name, message):
if not topic:
return
@ -115,4 +147,4 @@ def send_ntfy_notification(name, message):
except Exception as e:
print(f"Notification failed: {e}")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
app.run(host='0.0.0.0', port=5001)