utils

Display formatting and word counting utilities for the selection step

Word Operations


source

count_words


def count_words(
    text:str, # Text to count words in
)->int: # Word count

Count the number of whitespace-delimited words in text.

Date Formatting


source

format_date


def format_date(
    created_at:str, # ISO date string, Unix timestamp, or similar
)->str: # Formatted date for display

Format a date string for human-readable display (e.g., ‘Jan 20, 2026’).

Filename Formatting


source

format_audio_filename


def format_audio_filename(
    audio_path:str, # Full path to audio file
)->str: # Shortened filename for display

Extract and format the filename from a path.

Tests

assert count_words("") == 0
assert count_words("hello") == 1
assert count_words("The art of war") == 4
print("count_words tests passed")
assert format_date("") == "Unknown"
assert format_date(None) == "Unknown"
assert format_date("2026-01-20") == "Jan 20, 2026"
assert format_date("2026-01-20 14:30:00") == "Jan 20, 2026"
print("format_date tests passed")
assert format_audio_filename("/home/user/audio/test.wav") == "test.wav"
assert format_audio_filename("Unknown") == "Unknown Source"
assert format_audio_filename("") == "Unknown Source"
print("format_audio_filename tests passed")