{
 "nbformat": 4,
 "nbformat_minor": 5,
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# Retrofit Atlas quickstart\n\nA citable database of former malls and what became of them. No key. Research use only until the licence is agreed with the authors; cite record URLs. Docs: https://retrofitatlas.org/docs/ (built 2026-10-21)."
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import json, urllib.parse, urllib.request\nBASE = 'https://retrofitatlas.org'\ndef api(path, **params):\n    q = '&'.join(f'{k}={urllib.parse.quote(str(v))}' for k, v in params.items())\n    with urllib.request.urlopen(f'{BASE}/api/v1/{path}' + ('?' + q if q else '')) as r: return json.load(r)\nstats = api('stats'); stats['sites'], stats['by_status'][:5]",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Closed malls over 30 acres, largest first"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "r = api('sites', status='closed', min_acres=30, sort='acres', limit=25)\nfor s in r['results']: print(f\"{s['acres']:>6} ac  {s['name']}, {s['city']}, {s['state']}  {s['url']}\")",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## One record with everything (provenance, events, sources, deals, parcels, context layers)"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "rec = api('sites/m-31b5364d66')\nprint(rec['name'], rec['status'], rec['url'])\nprint('layers:', sorted(rec['context']))\nprint('tract:', rec['context'].get('tract'))",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Everything as a DataFrame (pandas optional)"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import pandas as pd\ndf = pd.read_csv('https://retrofitatlas.org/data/sites.csv')\ndf[df.country.eq('US')].groupby('status').size().sort_values(ascending=False)",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Sites near a point, and what changed this month"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "near = api('near', lat=34.187, lon=-118.397, km=40)\n[(s['km'], s['name']) for s in near['results'][:10]]",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "api('changes', since='2026-10-01', limit=10)['results'][:3]",
   "outputs": [],
   "execution_count": null
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Cite\n\nRetrofit Atlas (2026). Record <name>, https://retrofitatlas.org/<record url>, build 2026-10-21. Tier: see `verified` on the record."
  }
 ]
}