elon_py/pkg/dash/func/info.py
2025-03-06 13:59:37 +08:00

38 lines
1.3 KiB
Python

from pkg.dash.app_init import app
from dash.dependencies import Input, Output
from datetime import timedelta
import pytz
from datetime import datetime
from dash import html
@app.callback(
[Output('info-tooltip', 'children')],
[Input('clock-interval', 'n_intervals')]
)
def update_info(n):
table = html.Table([
html.Tr([html.Td('Pace(Xtracker)', style={'textAlign': 'center'}),
html.Td(calculate_tweet_pace(),style={'textAlign': 'center'})]),
], style={
'width': '100%',
'textAlign': 'left',
'borderCollapse': 'collapse'
})
return [table]
def calculate_tweet_pace():
est = pytz.timezone('US/Eastern')
now = datetime.now(est)
today = now.date()
days_to_next_friday = (4 - today.weekday()) % 7
if days_to_next_friday == 0:
days_to_next_friday = 7
next_friday = (now.replace(hour=12, minute=0, second=0, microsecond=0) +
timedelta(days=days_to_next_friday))
if now > next_friday:
next_friday += timedelta(days=7)
days_to_next_friday = (next_friday - now).total_seconds() / (24 * 60 * 60)
tweet_count = 440
pace = (tweet_count / (7 - days_to_next_friday)) * days_to_next_friday + tweet_count
return round(pace, 6) if pace > 0 else float(tweet_count)