mirror of
https://github.com/vinta/awesome-python.git
synced 2026-05-21 04:42:04 +08:00
refactor: replace manual total_seconds()/3600 with timedelta comparison
Use timedelta(hours=CACHE_MAX_AGE_HOURS) so the cache-age check reads at the intended hours unit directly, removing the conversion arithmetic. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -6,7 +6,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
from collections.abc import Sequence
|
from collections.abc import Sequence
|
||||||
from datetime import UTC, datetime
|
from datetime import UTC, datetime, timedelta
|
||||||
from itertools import batched
|
from itertools import batched
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -119,13 +119,13 @@ def main() -> None:
|
|||||||
cache = pruned
|
cache = pruned
|
||||||
|
|
||||||
# Determine which repos need fetching (missing or stale)
|
# Determine which repos need fetching (missing or stale)
|
||||||
|
max_age = timedelta(hours=CACHE_MAX_AGE_HOURS)
|
||||||
to_fetch = []
|
to_fetch = []
|
||||||
for repo in sorted(current_repos):
|
for repo in sorted(current_repos):
|
||||||
entry = cache.get(repo)
|
entry = cache.get(repo)
|
||||||
if entry and "fetched_at" in entry:
|
if entry and "fetched_at" in entry:
|
||||||
fetched = datetime.fromisoformat(entry["fetched_at"])
|
fetched = datetime.fromisoformat(entry["fetched_at"])
|
||||||
age_hours = (now - fetched).total_seconds() / 3600
|
if now - fetched < max_age:
|
||||||
if age_hours < CACHE_MAX_AGE_HOURS:
|
|
||||||
continue
|
continue
|
||||||
to_fetch.append(repo)
|
to_fetch.append(repo)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user