Skip to content

Instantly share code, notes, and snippets.

@tomislacker
Created February 17, 2021 21:20
Show Gist options
  • Save tomislacker/1cd13a420682bbf4933884c9a6752416 to your computer and use it in GitHub Desktop.
Save tomislacker/1cd13a420682bbf4933884c9a6752416 to your computer and use it in GitHub Desktop.
Quick hack to download and extract all dictionaries from huzheng.org for `sdcv`
#!/bin/bash
set -exo pipefail
HOST=http://download.huzheng.org/dict.org/
if [ -z "$STARDICT_DATA_DIR" ]
then
echo >&2 "Error: STARDICT_DATA_DIR not set!"
exit 1
fi
curl -s ${HOST} \
| grep -Eo 'href="[^\"]+"' \
| sed 's/href="\?//g; s/"\?$//g' \
| egrep '\.bz2$' \
| while read this_file;
do
echo "- $this_file"
dst_tarball=${STARDICT_DATA_DIR}/${this_file}
if [ -e "$dst_tarball" ]
then
echo >&2 "Skipping: ${this_file}"
continue
fi
# Download the file to a temporary location
wget \
-O ${dst_tarball} \
${HOST}${this_file}
# Extract the file
tar \
-xvj \
-f ${dst_tarball} \
-C ${STARDICT_DATA_DIR}
done
# vim:expandtab:ft=bash:sw=4:ts=4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment