diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1328b26 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +guestbook/* +import/* \ No newline at end of file diff --git a/app.py b/app.py index 61723f4..222d100 100644 --- a/app.py +++ b/app.py @@ -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) \ No newline at end of file + app.run(host='0.0.0.0', port=5001) \ No newline at end of file