[2024-10-12] Get user local time using Javascript

This commit is contained in:
Andrew Conlin 2024-10-12 16:21:53 +05:30
parent 7356b00de1
commit 13ec41e8a4
2 changed files with 33 additions and 7 deletions

View file

@ -1,7 +1,7 @@
import datetime
import math
from flask import Flask, render_template, url_for
from flask import Flask, render_template, url_for, request
app = Flask(__name__)
def num2day(num):
@ -136,8 +136,8 @@ def getHomoSapiens(yearPercent):
else:
return f"Homo Sapiens have been around for ~{-math.floor(yearsUntilHumans)} years."
def getTemplate():
now = datetime.datetime.now()
def getTemplate(timestamp):
now = datetime.datetime.fromtimestamp(timestamp)
nowTime = now.strftime("%-I:%M%p")
nowDate = now.strftime("%A") + " " + now.strftime("%-d") + " " + now.strftime("%B")
@ -155,10 +155,9 @@ def getTemplate():
return now.year, nowTime, nowDate, round(yearPercent*100,2), footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens
@app.route("/")
def index():
year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens = getTemplate()
cssPath = url_for('static', filename='style.css')
def index(timestamp):
year, nowTime, nowDate, yearPercent, footballMinute, workDay, workTime, marathonMile, abbeyRoadSong, hobbitChapter, lat, long, homoSapiens = getTemplate(timestamp)
cssPath = url_for("static", filename="style.css")
return render_template("index.html",\
cssPath=cssPath,\
year=year,\
@ -174,3 +173,12 @@ def index():
lat=lat,\
long=long,\
homoSapiens=homoSapiens)
@app.route("/", methods=["GET","POST"])
def init():
if request.method == "POST":
timestamp = int(request.values.get('timestamp'))
return index(timestamp)
else:
return render_template("init.html")