]>
Pierre Choffet | Git repositories - wdef_tools.git/blob - scripts/rdf.sh
3 # rdf.sh - Set of Bash functions to work with wdef files.
4 # Copyright (C) 2022 Pierre Choffet
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
8 # published by the Free Software Foundation.
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.
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/>.
20 readonly RDFS_CACHE_DIR
=${CACHE_DIR:-"${HOME}/.cache/wdef_tools/rdfs/"}
22 # Get RDF and return a path to the result into cache dir
26 # Path to the file containing the RDF, in cache dir
28 local -r element_qid
="${1}"
30 local -r rdf_url
="https://www.wikidata.org/wiki/Special:EntityData/${element_qid}.rdf"
31 local -r rdf_path
="${RDFS_CACHE_DIR}${element_qid}.xml"
34 mkdir -p "${RDFS_CACHE_DIR}"
36 curl
"${rdf_url}" > "${rdf_path}"
41 # Ensure RDF cache is not older than given age
44 # $2: Max age (in minutes)
46 # Path to the file containing the RDF, in cache dir
47 function cacheRDFMaxAge
() {
48 local -r element_qid
="${1}"
49 local -r max_age
="${2}"
51 local -r rdf_path
="${RDFS_CACHE_DIR}${element_qid}.xml"
53 if [ ! -f "${rdf_path}" ]||[[ $(find "${rdf_path}" -mmin "+${max_age}") ]]
55 cacheRDF
"${element_qid}"