From 6fe273d9d28d1767e7035fa30ae95a5546ce730f Mon Sep 17 00:00:00 2001 From: Abijah Date: Tue, 23 Jun 2026 09:47:19 -0700 Subject: [PATCH] Band Contacts to Google Contacts v2 --- band/band_contacts_to_google_contacts.py | 31 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/band/band_contacts_to_google_contacts.py b/band/band_contacts_to_google_contacts.py index 5c87ec3..290d254 100644 --- a/band/band_contacts_to_google_contacts.py +++ b/band/band_contacts_to_google_contacts.py @@ -3,6 +3,29 @@ import argparse import datetime import re +def clean_instrument_name(instrument_raw): + """Cleans the instrument name based on Percussion, Winds, and Default rules.""" + # Strip numerical prefix (e.g., "12 - Percussion (electronics)" -> "Percussion (electronics)") + if '-' in instrument_raw: + instrument = instrument_raw.split('-', 1)[-1].strip() + else: + instrument = instrument_raw.strip() + + lower_inst = instrument.lower() + + # 1. The Percussion Rule + if 'percussion' in lower_inst and '(' in instrument and ')' in instrument: + match = re.search(r'\((.*?)\)', instrument) + if match: + return match.group(1).strip().title() + + # 2. The Winds/General Rule + elif '(' in instrument and ')' in instrument: + return re.sub(r'\(.*?\)', '', instrument).strip() + + # 3. Default Rule + return instrument + def get_category(instrument): """Categorize the instrument into Woodwinds, Brass, Percussion, or Colorguard.""" inst_lower = instrument.lower() @@ -78,9 +101,9 @@ def main(): last_name = name_parts[0].strip() if len(name_parts) > 0 else "" first_name = name_parts[1].strip() if len(name_parts) > 1 else "" - # Parse Instrument (e.g., "04 - Tenor Sax" -> "Tenor Sax") + # Parse and Clean Instrument section_raw = row.get('SECTION', '').strip() - instrument = section_raw.split('-', 1)[-1].strip() if '-' in section_raw else section_raw + instrument = clean_instrument_name(section_raw) if not instrument: instrument = "Unknown" @@ -94,9 +117,9 @@ def main(): else: notes = grade_raw - # Determine Label + # Determine Label (Appended with Marching Band) category = get_category(instrument) - label = f"{target_year} {category} ::: Marching Band ::: * myContacts" + label = f"{target_year} {category} ::: Marching Band {target_year} ::: * myContacts" # Build the output row out_row = {key: "" for key in google_headers}