]> Pierre Choffet | Git repositories - wmo_to_wikidata.git/blob - demo.sh
Add WMO demonstration tools
[wmo_to_wikidata.git] / demo.sh
1 #!/bin/bash
2
3 # demo.sh - Process demonstration for WMO.
4 # Copyright (C) 2021 Pierre Choffet
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of version 3 of the GNU General Public License as published
8 # by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 set -euo pipefail
19
20 function usage {
21 cat << "EOF"
22 Import OSCAR station metadata to Wikidata
23
24 USAGE: intro.sh <wdef_file> <station_id>
25 EOF
26 }
27
28 function intro {
29 cat >&2 << "EOF"
30
31 .g8""8q. .M"""bgd .g8"""bgd db `7MM"""Mq. mm
32 .dP' `YM. ,MI "Y .dP' `M ;MM: MM `MM. MM
33 dM' `MM `MMb. dM' ` ,V^MM. MM ,M9 mmMMmm ,pW"Wq.
34 MM MM `YMMNq. MM ,M `MM MMmmdM9 MM 6W' `Wb
35 MM. ,MP . `MM MM. AbmmmqMA MM YM. MM 8M M8
36 `Mb. ,dP' Mb dM `Mb. ,' A' VML MM `Mb. MM YA. ,A9
37 `"bmmd"' P"Ybmmd" `"bmmmd'.AMA. .AMMA..JMML. .JMM. `Mbmo`Ybmd9'
38
39 ,, ,, ,,
40 `7MMF' A `7MF'db `7MM db `7MM mm
41 `MA ,MA ,V MM MM MM
42 VM: ,VVM: ,V `7MM MM ,MP'`7MM ,M""bMM ,6"Yb.mmMMmm ,6"Yb.
43 MM. M' MM. M' MM MM ;Y MM ,AP MM 8) MM MM 8) MM
44 `MM A' `MM A' MM MM;Mm MM 8MI MM ,pm9MM MM ,pm9MM
45 :MM; :MM; MM MM `Mb. MM `Mb MM 8M MM MM 8M MM
46 VF VF .JMML..JMML. YA..JMML.`Wbmd"MML.`Moo9^Yo.`Mbmo`Moo9^Yo.
47
48
49 This tool has been written in 2021 as a one-time proof of concept to import
50 Oscar station metadata into Wikidata. It's not meant to be used outside of this
51 controlled environment as it would inevitably lead any careful user to
52 insert duplicates and wrong information into the Wikimedia project.
53
54 The full original code remains available here for educational purpose.
55
56 For up to date code, see the repository at
57 <https://git.choffet.net/?p=wmo_to_wikidata.git>
58 EOF
59 }
60
61 # Check user args
62 if [ "$#" -ne 2 ]
63 then
64 usage
65 exit
66 elif [ ! -f "${1}" ]
67 then
68 echo "File \"${1}\" doesn't exist." >&2
69 exit
70 fi
71
72 intro
73 exit 1
74
75 # Generate partial wdef file
76 PARTIAL_WDEF_PATH="$(mktemp)"
77 xmlstarlet tr xslts/isolate_station.xslt -s "wigos-id=${2}" "${1}" | xmlstarlet fo > "${PARTIAL_WDEF_PATH}"
78
79 # Import it
80 ./import.sh "${PARTIAL_WDEF_PATH}" elements.log
81 rm "${PARTIAL_WDEF_PATH}"
82 echo "Import done" >&2