diff options
Diffstat (limited to 'util')
-rwxr-xr-x | util/bin/dict.leo.org | 87 | ||||
-rwxr-xr-x | util/bin/hrefs | 20 |
2 files changed, 107 insertions, 0 deletions
diff --git a/util/bin/dict.leo.org b/util/bin/dict.leo.org new file mode 100755 index 00000000..6a9d9669 --- /dev/null +++ b/util/bin/dict.leo.org @@ -0,0 +1,87 @@ +#! /bin/sh +#### dict.leo.org version 2.0 beta 1 +set -euf + +cache_dir=/tmp/dict.leo.org/ +file="$cache_dir$*" + +url="http://dict.leo.org/?$*" + +# TODO check sanity of filename + +if test -d "$cache_dir" ; then + test -e "$file" || { curl --silent "$url" | tee "$file" ; } +else + curl --silent "$url" +fi | +sed 's/>\( *.\)/>\n\1/g' | sed -rn ' + s/[[:space:]]/ /g + /<!-- # Werbung # -->/,/<\/td>/b + /<!-- ============================================== -->/,/^<\/td>/b + /<!-- # Trailer # -->/,/^ <\/table>/b + /<table id="subnavigation" class="border">/,/<\/table>/b + /<div id="divMoreInfo" class="popup">/,/^ <\/table>/b + + ## show link in rendered version + s/^<a href="(.*searchLocRelinked.*)">$/&mehr: \1/ + s/^mehr >>// + + s/<[Bb][Rr] *\/>/,/g + + p + b + :c;# comment + s/-->/\\-\\-\\>/g + s/<!--/\\<\\!\\-\\-/g + s/.*/<!--(&)-->/ + p +' \ +| w3m -cols 1024 -T text/html -dump | sed -r ' + s/[[:space:]]+/ /g + s/ ,/,/g + s/^ //;s/ $// + s/[┌┬┐└┴┘├┼┤─]//g + s/ *│ */|/g + s/\[ \]// + s/\[Speichern\] der ausgewa:hlten Wo:rter im Trainer// + s/^\|\|//;s/\|\| ?$// +' | sed -rn ' + /^\[EN-> DE\]/,$b + s/^mehr: /+ / + s/^ENGLISCH\|\|DEUTSCH ?/= Englisch -> Deutsch/ + s/^\|([0-9]+) (Treffer)\|$/= \1 \2/ + s/^([^|]+)\|\|([^|]+)$/- \1|\2/ + + s/^[^=+#-][^|]+$/## &/ + + p +' | sed -rn ' + /^$/b + s/ ([?!])/\1/g + s/([[(]) /\1/g;s/ ([])])/\1/g + + s/ \([0-9]+ of [0-9]+\) ?//;# TODO + + #s/^##.*Grundform.*/\n#&/ + /^## .*Grundform.*/,/^##( .*)?/{ + /##/{/Grundform/!p} + b + } + + /^## Informationen /,$b;# TODO + #/^## Beispiele/,$b;# TODO + #/^## Wendungen/,$b;# TODO + /^\+/b;# TODO + #/^=/b;# TODO + + p +' | sed -r ' + ## + s/\|(.*)/\n [32m\1[m/g + s/^#.*/\n[33m&[m/ + + s/##.*Treffer $/\n[1;33m#&[m/ +' | less -R +echo + +#### end of file. diff --git a/util/bin/hrefs b/util/bin/hrefs new file mode 100755 index 00000000..3a1a51de --- /dev/null +++ b/util/bin/hrefs @@ -0,0 +1,20 @@ +#! /bin/sh + +_hrefs() { + sed -n 's/href="\([^"]\+\)"/\n&\n/gp' | + sed -n 's/^href="\([^"]\+\)"$/\1/p'; } + +_add_prefix_to_relative_hrefs() { + sed '/^http:/!s^'"$1"''; } + +_main() { + case $# in + (0) _hrefs;; + (1) _hrefs | _add_prefix_to_relative_hrefs "$1";; + (*) + echo "bad command line: $0 $*" >&2; exit 23;; + esac; } + +set -euf +_main "$@" +#### end of file. |