diff --git a/.github/workflows/update-stats.yml b/.github/workflows/update-stats.yml index f4ce9a3..967ca77 100644 --- a/.github/workflows/update-stats.yml +++ b/.github/workflows/update-stats.yml @@ -15,7 +15,7 @@ jobs: steps: - name: Random delay (0-7 minutes) run: | - RANDOM_SECONDS=$((RANDOM % 1)) + RANDOM_SECONDS=$((RANDOM % 420)) echo "Waiting for $RANDOM_SECONDS seconds to randomize execution time..." sleep $RANDOM_SECONDS diff --git a/manual_update.py b/manual_update.py index 8215586..f3a4db1 100644 --- a/manual_update.py +++ b/manual_update.py @@ -6,7 +6,7 @@ import json import os -from datetime import datetime +from datetime import datetime, timezone, timedelta def get_manual_stats(): @@ -59,7 +59,9 @@ def get_manual_stats(): def save_last_known_counts(stats): """Save the manually entered statistics as last known counts.""" - current_date = datetime.now().strftime('%Y-%m-%d') + # Use BDT timezone (UTC+6) for consistency + bdt_tz = timezone(timedelta(hours=6)) + current_date = datetime.now(bdt_tz).strftime('%Y-%m-%d') # Load existing data last_known = {'counts': {}, 'dates': {}, 'modes': {}} @@ -129,7 +131,8 @@ def main(): success = update_readme.update_readme(stats, last_known_info=last_known_info, update_source='manual') if success: print("\n✓ README.md has been updated successfully!") - print(f" Last updated: {datetime.now().strftime('%d %B %Y')}") + bdt_tz = timezone(timedelta(hours=6)) + print(f" Last updated: {datetime.now(bdt_tz).strftime('%d %B %Y')}") else: print("\n✗ Failed to update README.md") else: diff --git a/update_readme.py b/update_readme.py index 2583b61..6e88729 100644 --- a/update_readme.py +++ b/update_readme.py @@ -273,16 +273,21 @@ def update_readme(stats, last_known_info=None, update_source=None): percentage = calculate_percentage(count_effective, total) # Pick date to display: - # - If freshly fetched with 'automatic' mode: use current date + # - If freshly fetched today (date matches today): use current date # - Otherwise: use last-known date (for manual updates or cached data) platform_mode = last_known_modes.get(platform, 'automatic') + raw_date = last_known_dates.get(platform) - if platform in stats and stats[platform] is not None and platform_mode == 'automatic': - # Freshly fetched automatically today - use current date + # Check if data was freshly fetched today by comparing dates + is_fresh_today = (platform in stats and + stats[platform] is not None and + raw_date == today_iso) + + if is_fresh_today: + # Freshly fetched today - use current date date_str = current_date else: # Using cached/manual value - show the cached date - raw_date = last_known_dates.get(platform) if raw_date: date_str = _format_human_date(raw_date) else: diff --git a/update_stats.py b/update_stats.py index 170a76d..daa8b09 100755 --- a/update_stats.py +++ b/update_stats.py @@ -34,7 +34,7 @@ import os from urllib.request import urlopen, Request from urllib.error import URLError, HTTPError -from datetime import datetime +from datetime import datetime, timezone, timedelta from bs4 import BeautifulSoup @@ -94,7 +94,9 @@ def _update_last_known(self, platform, count, mode=None): self.last_known_counts['modes'] = {} self.last_known_counts['counts'][platform] = count - self.last_known_counts['dates'][platform] = datetime.now().strftime('%Y-%m-%d') + # Use BDT timezone (UTC+6) for consistency with update_readme.py + bdt_tz = timezone(timedelta(hours=6)) + self.last_known_counts['dates'][platform] = datetime.now(bdt_tz).strftime('%Y-%m-%d') # Update the mode only if it is different from the existing one if mode is not None and self.last_known_counts['modes'].get(platform) != mode: