"""
GLAMWalk -- Volume 3: Data at Scale
01_new_grammar_examples.py

Runnable examples for this volume's new concepts: argparse command-line flags, and extending try/except with continue.

Source: Volume Three, New Grammar for This Volume
Targets Python 3.11.4 -- see Volume One, Chapter 1.5/1.6.
"""

import argparse

parser = argparse.ArgumentParser()
parser.add_argument("--commit", action="store_true",
                     help="Actually write to the database. Without this flag, dry-run only.")
args = parser.parse_args()

if args.commit:
    print("Running for real.")
else:
    print("Dry run only.")


def run_import(name):
    """Stand-in for a real per-institution import function — see
    Volume Three, Chapters 2-7 for the real NGA/Cooper Hewitt/etc.
    importers this would call in a real pipeline."""
    print(f"(pretending to import {name})")

for name in ["nga", "cooper_hewitt", "cleveland"]:
    try:
        run_import(name)
    except Exception as e:
        print(f"FAILED: {name}: {e}")
        continue   # move on to the next institution instead of stopping the whole run
