mirror of
https://github.com/vinta/awesome-python.git
synced 2026-03-24 01:24:43 +08:00
refactor(website): hoist loop-invariant variables outside the fetch loop
now_iso and total_batches were recomputed on every iteration. Moving them above the loop makes intent clearer and avoids redundant work. Also simplifies cache dict construction with dict unpacking. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -136,6 +136,9 @@ def main() -> None:
|
|||||||
fetched_count = 0
|
fetched_count = 0
|
||||||
skipped_repos: list[str] = []
|
skipped_repos: list[str] = []
|
||||||
|
|
||||||
|
now_iso = now.isoformat()
|
||||||
|
total_batches = (len(to_fetch) + BATCH_SIZE - 1) // BATCH_SIZE
|
||||||
|
|
||||||
with httpx.Client(
|
with httpx.Client(
|
||||||
headers={"Authorization": f"bearer {token}", "Content-Type": "application/json"},
|
headers={"Authorization": f"bearer {token}", "Content-Type": "application/json"},
|
||||||
transport=httpx.HTTPTransport(retries=2),
|
transport=httpx.HTTPTransport(retries=2),
|
||||||
@@ -144,7 +147,6 @@ def main() -> None:
|
|||||||
for i in range(0, len(to_fetch), BATCH_SIZE):
|
for i in range(0, len(to_fetch), BATCH_SIZE):
|
||||||
batch = to_fetch[i : i + BATCH_SIZE]
|
batch = to_fetch[i : i + BATCH_SIZE]
|
||||||
batch_num = i // BATCH_SIZE + 1
|
batch_num = i // BATCH_SIZE + 1
|
||||||
total_batches = (len(to_fetch) + BATCH_SIZE - 1) // BATCH_SIZE
|
|
||||||
print(f"Fetching batch {batch_num}/{total_batches} ({len(batch)} repos)...")
|
print(f"Fetching batch {batch_num}/{total_batches} ({len(batch)} repos)...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -158,15 +160,9 @@ def main() -> None:
|
|||||||
save_cache(cache)
|
save_cache(cache)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
now_iso = now.isoformat()
|
|
||||||
for repo in batch:
|
for repo in batch:
|
||||||
if repo in results:
|
if repo in results:
|
||||||
cache[repo] = {
|
cache[repo] = {**results[repo], "fetched_at": now_iso}
|
||||||
"stars": results[repo]["stars"],
|
|
||||||
"owner": results[repo]["owner"],
|
|
||||||
"last_commit_at": results[repo]["last_commit_at"],
|
|
||||||
"fetched_at": now_iso,
|
|
||||||
}
|
|
||||||
fetched_count += 1
|
fetched_count += 1
|
||||||
else:
|
else:
|
||||||
skipped_repos.append(repo)
|
skipped_repos.append(repo)
|
||||||
|
|||||||
Reference in New Issue
Block a user