]>
Wikimedia Canada | Git repositories - eccc_to_commons.git/blob - eccc_merger.sh
3 # eccc_merger.sh - Merge Environment and Climate change Canada historical data
4 # Copyright (C) 2020, 2021 Pierre Choffet
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 Merge XMLs provided by Environment and Climate change Canada
27 Usage: eccc_merger.sh <ECCC XML path> <ECCC XML path> [ECCC XML path […]]
29 At least two XML files must be provided for them to be merged (obviously…).
30 Subsequent files will be merged as well, result is written to standard
32 All XMLs must be valid to commons_rules.xsd and be same type (monthly or
38 # Auto detect input types
45 echo "File ${path} doesn't exist" >&2
50 FILE_TYPE
=$(xmlstarlet sel -t -i '/climatedata/month' -o almanach --elif '/climatedata/stationdata' -o monthly --else -o '' "${path}")
52 if [ "${MERGE_TYPE}" != '' ]
54 if [ "${FILE_TYPE}" != "${MERGE_TYPE}" ]
56 echo 'All XMLs must be the same type' >&2
60 MERGE_TYPE
="${FILE_TYPE}"
64 # Select stylesheet to be used
65 if [ "${MERGE_TYPE}" == 'almanach' ]
67 STYLESHEET
='eccc_merger_almanach.xslt'
68 elif [ "${MERGE_TYPE}" == 'monthly' ]
70 STYLESHEET
='eccc_merger_monthly.xslt'
71 echo 'Not working with monthly data for now. Exiting.'
79 if [ "${FIRST_PASS}" -eq 1 ]
82 FIRST_PATH
="$(mktemp)"
83 cp "${path}" "${FIRST_PATH}"
89 xmlstarlet
tr "${STYLESHEET}" -s "merge-path=${SECOND_PATH}" "${FIRST_PATH}" > "${OUT_PATH}"
92 FIRST_PATH
="${OUT_PATH}"