X-Git-Url: https://git.wikimedia.ca/?p=eccc_to_commons.git;a=blobdiff_plain;f=eccc_to_commons.sh;h=f6d399b67fe8028ca26475d128d15a9c474e90f6;hp=5d7b01071c177c6f81abaf4dfe7d4c5a85195f31;hb=refs%2Fheads%2Fmaster;hpb=0673c779d48ec15e66ab666ffc573daf56e8e714 diff --git a/eccc_to_commons.sh b/eccc_to_commons.sh index 5d7b010..f6d399b 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,20 @@ 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 + # Check file contains data + declare -i AL_DAY_COUNT=$(xmlstarlet sel -t -v 'count(//day)' "${REPLY}") + if [ ${AL_DAY_COUNT} -eq 0 ] + then + echo "${REPLY}: No day found. Ignoring." >&2 + continue + fi + 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