Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created July 1, 2026 04:01
Show Gist options
  • Select an option

  • Save ahoward/47048ebc109a75916c48324d720a3272 to your computer and use it in GitHub Desktop.

Select an option

Save ahoward/47048ebc109a75916c48324d720a3272 to your computer and use it in GitHub Desktop.
nice-rid — resolve subreddit names to Reddit/SocialGist t5_ ids (for the NICE pipeline config/pilot.yml)
#!/usr/bin/env bash
#
# nice-rid — resolve subreddit names to their internal SocialGist/Reddit t5_ ids
#
# WHY: the 'nice' pipeline's config/pilot.yml needs, per subreddit, the Reddit
# "fullname" (t5_...), which SocialGist/BoardReader calls `filter_site_key`.
# Reddit blocks datacenter IPs on its .json API, so this must run from a normal
# machine (residential IP / logged-in browser session).
#
# USAGE:
# bash nice-rid.sh # uses the built-in NICE subreddit list
# bash nice-rid.sh ACL ORIF ... # or pass your own names
#
# OUTPUT:
# 1. a human table: subreddit t5_id subscribers
# 2. a ready-to-paste YAML block for config/pilot.yml
#
set -euo pipefail
SUBS=("$@")
if [ ${#SUBS[@]} -eq 0 ]; then
SUBS=(
Kneereplacement TotalHipReplacement ACL KneeInjuries
ShoulderSurgery RotatorCuff ShoulderInjuries ORIF AchillesRupture
)
fi
UA='Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
# batch-fetch all subs in one api/info call
CSV=$(IFS=,; echo "${SUBS[*]}")
JSON=$(curl -sS --compressed \
-H "user-agent: $UA" \
-H 'accept: application/json' \
"https://www.reddit.com/api/info.json?sr_name=${CSV}" || true)
# parse with python (present everywhere); tolerate blocks/partial results
python3 - "$JSON" <<'PY'
import sys, json
raw = sys.argv[1] if len(sys.argv) > 1 else ""
try:
d = json.loads(raw)
children = d["data"]["children"]
except Exception:
sys.stderr.write(
"\n!! could not parse Reddit response — you're likely blocked or logged out.\n"
" Open this URL in a browser where you're logged into reddit.com,\n"
" then re-run this script from that machine:\n\n"
" https://www.reddit.com/api/info.json?sr_name=" + "%s\n\n" % raw[:0]
)
if raw:
sys.stderr.write(" raw response (first 300 chars):\n " + raw[:300].replace("\n"," ") + "\n\n")
sys.exit(2)
rows = []
for c in children:
data = c.get("data", {})
rows.append((
data.get("display_name", "?"),
data.get("name", "?"), # t5_...
data.get("subscribers"),
data.get("subreddit_type"),
))
# table
w = max((len(r[0]) for r in rows), default=10) + 2
print("\nSUBREDDIT".ljust(w+2) + "T5_ID".ljust(16) + "SUBS".rjust(10) + " TYPE")
print("-" * (w + 2 + 16 + 12 + 8))
for name, t5, subs, typ in sorted(rows, key=lambda r: r[0].lower()):
subs_s = f"{subs:,}" if isinstance(subs, int) else "?"
print(("r/"+name).ljust(w+2) + str(t5).ljust(16) + subs_s.rjust(10) + f" {typ or '?'}")
# yaml block for pilot.yml
print("\n# ---- paste into config/pilot.yml ----")
print("subreddits:")
for name, *_ in sorted(rows, key=lambda r: r[0].lower()):
print(f" - r/{name}")
print("\nsocial_gist:")
print(" subreddits:")
for name, t5, *_ in sorted(rows, key=lambda r: r[0].lower()):
print(f" r/{name}: {t5}")
print()
PY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment