update time format to internet time
This commit is contained in:
parent
da83e1e956
commit
62e001a6b7
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
guestbook/*
|
||||||
|
import/*
|
||||||
40
app.py
40
app.py
@ -2,7 +2,8 @@ import os
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
from datetime import datetime
|
import math
|
||||||
|
from datetime import datetime, timezone, timedelta
|
||||||
from flask import Flask, request, jsonify
|
from flask import Flask, request, jsonify
|
||||||
from flask_cors import CORS
|
from flask_cors import CORS
|
||||||
|
|
||||||
@ -12,7 +13,11 @@ app = Flask(__name__)
|
|||||||
DAILY_LIMIT = 50
|
DAILY_LIMIT = 50
|
||||||
DATA_DIR = 'guestbook'
|
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
|
submissionCountDay = 0
|
||||||
|
|
||||||
|
|
||||||
@ -71,11 +76,14 @@ def addComment():
|
|||||||
if not website.startswith(('http://', 'https://')):
|
if not website.startswith(('http://', 'https://')):
|
||||||
website = 'https://' + website
|
website = 'https://' + website
|
||||||
|
|
||||||
|
date_str=time.strftime("%d-%m-%Y")
|
||||||
|
itime_beats=itime()
|
||||||
|
|
||||||
entry = {
|
entry = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'message': message,
|
'message': message,
|
||||||
'website': website,
|
'website': website,
|
||||||
'date': time.strftime("%d-%m-%Y %H:%M")
|
'date': f"{date_str} @{itime_beats:03d}"
|
||||||
}
|
}
|
||||||
|
|
||||||
now = datetime.now()
|
now = datetime.now()
|
||||||
@ -103,6 +111,30 @@ def addComment():
|
|||||||
|
|
||||||
return jsonify({"status": "success"})
|
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):
|
def send_ntfy_notification(name, message):
|
||||||
if not topic:
|
if not topic:
|
||||||
return
|
return
|
||||||
@ -115,4 +147,4 @@ def send_ntfy_notification(name, message):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Notification failed: {e}")
|
print(f"Notification failed: {e}")
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host='0.0.0.0', port=5000)
|
app.run(host='0.0.0.0', port=5001)
|
||||||
Loading…
Reference in New Issue
Block a user