"""
GLAMWalk -- Volume 1: Foundations
05_csv_bulk_metadata.py

Reading the Met's bulk CC0 metadata export locally with csv.DictReader -- no network required if you have a copy of MetObjects.csv. Shows the csv.field_size_limit fix needed for real museum exports.

Source: Volume One, Section 2.4 -- The Bulk Alternative
Targets Python 3.11.4 -- see Volume One, Chapter 1.5/1.6.
"""

import csv

# The Met publishes their full open-access metadata as one CSV.
# Files this large sometimes exceed Python's default per-field size limit,
# so we raise it defensively before reading.
csv.field_size_limit(10_000_000)

pd_count = 0
with open("MetObjects.csv", newline="", encoding="utf-8") as f:
    reader = csv.DictReader(f)
    for row in reader:
        if row.get("Is Public Domain") == "True":
            pd_count += 1

print(f"{pd_count} confirmed public-domain objects in this export.")
