From a0f436c98fea268033e39292a18c43d457fbf325 Mon Sep 17 00:00:00 2001 From: NY Date: Thu, 6 Mar 2025 13:59:37 +0800 Subject: [PATCH] fix --- pkg/dash/func/info.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 pkg/dash/func/info.py diff --git a/pkg/dash/func/info.py b/pkg/dash/func/info.py new file mode 100644 index 0000000..a1a4d97 --- /dev/null +++ b/pkg/dash/func/info.py @@ -0,0 +1,38 @@ +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) \ No newline at end of file