← All repositories

crossmate

A collaborative crossword app for iPhone and iPad

git clone https://code.inqk.net/crossmate.git


Scripts/fetch-nyt.sh (1392B)

1#!/usr/bin/env bash
2#
3# Fetch a NYT crossword puzzle's raw v6 JSON for inspection.
4#
5# Usage:
6#   ./Scripts/fetch-nyt.sh [YYYY-MM-DD] [output-path]
7#
8# Defaults: today (America/New_York), nyt-<date>.json in the cwd.
9# The NYT-S cookie is read from cookies.txt at the repo root (gitignored).
10# Get the value from a signed-in browser session
11# (DevTools → Application → Cookies → https://www.nytimes.com).
12# Override by setting NYT_S in the environment.
13
14set -euo pipefail
15
16repo_root="$(cd "$(dirname "$0")/.." && pwd)"
17cookie_file="${repo_root}/cookies.txt"
18
19if [[ -z "${NYT_S:-}" ]]; then
20    if [[ -f "$cookie_file" ]]; then
21        NYT_S="$(tr -d '[:space:]' < "$cookie_file")"
22    fi
23fi
24
25if [[ -z "${NYT_S:-}" ]]; then
26    echo "error: NYT-S cookie not found" >&2
27    echo "  put the cookie value in ${cookie_file}, or set NYT_S in the environment" >&2
28    exit 1
29fi
30
31date_arg="${1:-$(TZ=America/New_York date +%Y-%m-%d)}"
32out_path="${2:-nyt-${date_arg}.json}"
33
34url="https://www.nytimes.com/svc/crosswords/v6/puzzle/daily/${date_arg}.json"
35
36http_code=$(curl -sS \
37    -H "Cookie: NYT-S=${NYT_S}" \
38    -o "${out_path}" \
39    -w "%{http_code}" \
40    "${url}")
41
42if [[ "${http_code}" != "200" ]]; then
43    echo "error: HTTP ${http_code}" >&2
44    echo "body:" >&2
45    cat "${out_path}" >&2
46    rm -f "${out_path}"
47    exit 1
48fi
49
50echo "saved ${out_path} ($(wc -c < "${out_path}") bytes)"