X-Git-Url: https://git.wikimedia.ca/?a=blobdiff_plain;f=eccc_to_commons.sh;h=5381bb5933d8f1bc3903f2ef9ee1134b061f558e;hb=841ebb7ac88358738d28a2f096c031de51c685ad;hp=5d7b01071c177c6f81abaf4dfe7d4c5a85195f31;hpb=0673c779d48ec15e66ab666ffc573daf56e8e714;p=eccc_to_commons.git diff --git a/eccc_to_commons.sh b/eccc_to_commons.sh index 5d7b010..5381bb5 100755 --- a/eccc_to_commons.sh +++ b/eccc_to_commons.sh @@ -42,20 +42,20 @@ do declare -i MINUTE_COUNT=$(xmlstarlet sel -t -v 'count(//stationdata[@minute])' "${REPLY}") declare -i AL_MONTH_COUNT=$(xmlstarlet sel -t -v 'count(//month)' "${REPLY}") - # Detect station id - declare -i LAST_DIR=$(basename $(dirname "${REPLY}")) - declare -i FILENAME=$(basename "${REPLY%.*}") + # Detect climate id + declare LAST_DIR=$(basename $(dirname "${REPLY}")) + declare FILENAME=$(basename "${REPLY%.*}") - if [ "${LAST_DIR}" -gt 0 ] + if [[ "${LAST_DIR}" =~ ^[A-Z0-9]{7}$ ]] then - # Station id is in last directory name - STATION_ID="${LAST_DIR}" - elif [ "${FILENAME}" -gt 0 ] + # Climate id is in last directory name + CLIMATE_ID="${LAST_DIR}" + elif [[ "${FILENAME}" =~ ^[A-Z0-9]{7}$ ]] then - # Station id is in file name - STATION_ID="${FILENAME}" + # Climate id is in file name + CLIMATE_ID="${FILENAME}" else - echo "${REPLY}: Cannot detect station id" + echo "${REPLY}: Cannot detect climate id" exit 1 fi @@ -88,12 +88,12 @@ do [ ${MINUTE_COUNT} -eq 0 ] then STYLESHEET_PATH='monthly_to_commons.xslt' - DESTINATION_PATH="${DESTINATION}/weather.gc.ca/Monthly/${STATION_ID}.tab" + DESTINATION_PATH="${DESTINATION}/weather.gc.ca/Monthly/${CLIMATE_ID}.tab" elif [ ${STATIONDATA_COUNT} -eq 0 ]&& \ [ ${AL_MONTH_COUNT} -gt 0 ] then STYLESHEET_PATH='almanac_to_commons.xslt' - DESTINATION_PATH="${DESTINATION}/weather.gc.ca/Almanac/${STATION_ID}.tab" + DESTINATION_PATH="${DESTINATION}/weather.gc.ca/Almanac/${CLIMATE_ID}.tab" else echo "${REPLY}: Cannot detect file type. Exiting." exit 1