elon_py/pkg/dash/func/clock.py
2025-03-05 10:44:38 +08:00

31 lines
1006 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import pytz
from pkg.dash.app_init import app
from dash.dependencies import Input, Output
from pkg.config import pacific,central,eastern
from datetime import datetime
from dash import html
@app.callback(
[Output('pst-clock', 'children')],
[Input('clock-interval', 'n_intervals')]
)
def update_clocks(n):
now_utc = datetime.now(pytz.UTC)
pst_time = now_utc.astimezone(pacific).strftime('%Y-%m-%d %H:%M:%S PST')
cst_time = now_utc.astimezone(central).strftime('%Y-%m-%d %H:%M:%S CST')
est_time = now_utc.astimezone(eastern).strftime('%Y-%m-%d %H:%M:%S EST')
table = html.Table([
html.Tr([html.Td('𝕏', style={'textAlign': 'center'}), html.Td(pst_time)]),
html.Tr([html.Td('🚀', style={'textAlign': 'center'}), html.Td(cst_time)]),
html.Tr([html.Td('🏛️🌴', style={'textAlign': 'center'}), html.Td(est_time)])
], style={
'width': '100%',
'textAlign': 'left',
'borderCollapse': 'collapse'
})
return [table]