Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/update-stats.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions manual_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import json
import os
from datetime import datetime
from datetime import datetime, timezone, timedelta


def get_manual_stats():
Expand Down Expand Up @@ -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': {}}
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 9 additions & 4 deletions update_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions update_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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:
Expand Down
Loading