name = "locale_weather_url" category = "pipeline" mode = "convert" description = """ Construct weather API URLs from locale and location information. Read lines from stdin in the format: LANG_CODE LOCATION where LANG_CODE is a 2-letter locale (e.g., "en", "fr", "de") and LOCATION is a city/place name (may contain spaces). For each line, construct a URL in the format: https://LANG.wttr.in/LOCATION Where spaces in the location are replaced with "+" characters. If LANG_CODE is empty or invalid (not exactly 2 lowercase letters), default to "en". Skip empty lines. Output one URL per input line. """ bash_source = ''' #!/bin/bash while IFS= read -r line || [[ -n "$line" ]]; do [[ -z "$line" ]] && continue # Extract lang code (first field) lang=$(echo "$line" | awk '{print $1}') # Extract location (everything after first field) location=$(echo "$line" | sed 's/^[^ ]* *//') # Validate lang code: must be exactly 2 lowercase letters if [[ ! "$lang" =~ ^[a-z]{2}$ ]]; then lang="en" fi # If location is same as lang (single-word line), skip if [[ "$location" == "$lang" || -z "$location" ]]; then location="" fi # Replace spaces with + location=$(echo "$location" | tr ' ' '+') echo "https://$lang.wttr.in/$location" done ''' [[test_cases]] description = "Various locales and locations" stdin = """en New York fr Paris de Berlin ja Tokyo""" expected_stdout = """https://en.wttr.in/New+York https://fr.wttr.in/Paris https://de.wttr.in/Berlin https://ja.wttr.in/Tokyo""" [[test_cases]] description = "Multi-word locations" stdin = """en San Francisco es Buenos Aires pt Rio de Janeiro""" expected_stdout = """https://en.wttr.in/San+Francisco https://es.wttr.in/Buenos+Aires https://pt.wttr.in/Rio+de+Janeiro""" [[test_cases]] description = "Invalid or missing locale defaults to en" stdin = """ENG London 123 Moscow x Rome""" expected_stdout = """https://en.wttr.in/London https://en.wttr.in/Moscow https://en.wttr.in/Rome"""