Skip to content
Open
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The agent can't send mail directly — its Gmail connector only exposes `create_
### 1. Google Cloud credentials

- In Google Cloud Console, create a project and enable both the **Google Calendar API** and the **Gmail API**
- Configure the **OAuth consent screen**: External user type, app name of your choice, scopes `.../auth/calendar` and `.../auth/gmail.modify`, add yourself as a Test user (the app can stay in "Testing" status)
- Configure the **OAuth consent screen**: External user type, app name of your choice, scopes `.../auth/calendar` and `.../auth/gmail.modify`, add yourself as a Test user, then **click "Publish app"** so the status is "In production" — an app left in "Testing" makes Google expire the refresh token after 7 days, which silently breaks `send_outbox.py`
- Create an **OAuth client ID** of type **Desktop app** and download the JSON as `client_secret.json`

### 2. Mint a refresh token locally
Expand Down
30 changes: 24 additions & 6 deletions fetch_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
data/leetcode_daily.json — LeetCode's daily challenge (fresh each day)
"""
import json
import time
from datetime import datetime, timedelta, timezone
from pathlib import Path

Expand All @@ -23,16 +24,33 @@
HANDLE = "Omar_Musayev"
DATA_DIR = Path(__file__).parent / "data"
TIMEOUT = 60
RETRIES = 4
RETRY_BACKOFF = [3, 8, 20] # seconds to wait before retry attempts 2, 3, 4
NOW = datetime.now(timezone.utc)


def cf_get(url):
r = requests.get(url, timeout=TIMEOUT)
r.raise_for_status()
data = r.json()
if data.get("status") != "OK":
raise RuntimeError(f"{url}: {data.get('status')}: {data.get('comment')}")
return data["result"]
"""GET a Codeforces API endpoint, retrying transient network/API failures.

The Codeforces API intermittently times out or returns a non-OK status;
a single blip should not fail the whole run, so retry with backoff.
"""
last_err = None
for attempt in range(RETRIES):
try:
r = requests.get(url, timeout=TIMEOUT)
r.raise_for_status()
data = r.json()
if data.get("status") != "OK":
raise RuntimeError(f"{url}: {data.get('status')}: {data.get('comment')}")
return data["result"]
except (requests.exceptions.RequestException, RuntimeError) as e:
last_err = e
if attempt + 1 < RETRIES:
delay = RETRY_BACKOFF[attempt]
print(f"cf_get failed (attempt {attempt + 1}/{RETRIES}): {e} — retrying in {delay}s")
time.sleep(delay)
raise RuntimeError(f"cf_get gave up after {RETRIES} attempts: {url}: {last_err}")


def write_json(path: Path, payload: dict):
Expand Down