summaryrefslogtreecommitdiffstats
path: root/util/bin/dic
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-09-02 16:36:57 +0200
committermakefu <github@syntax-fehler.de>2013-09-02 16:36:57 +0200
commitb6ab9e12dd5422f8b65601d10955486778242ede (patch)
tree008c2dfd7c88c52b0726585f5e532b853bbd49b7 /util/bin/dic
parent191851dc1df4663159f155d8df74477267510fc1 (diff)
parent66348d1a0399501ca354e09101ff981c370f20fb (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'util/bin/dic')
-rwxr-xr-xutil/bin/dic68
1 files changed, 68 insertions, 0 deletions
diff --git a/util/bin/dic b/util/bin/dic
new file mode 100755
index 00000000..aceee6e6
--- /dev/null
+++ b/util/bin/dic
@@ -0,0 +1,68 @@
+#! /bin/sh
+# usage: dic WORD [LANG]
+# where LANG may be one of en, fr, es, it, ch, ru, pt, pl
+# multiple WORDs may be seperated by + like this: multiple+words
+set -euf
+
+# all three are used by GET
+search="$1"
+langlang="${2-en}de"
+lang="de"
+
+main() {
+ GET | simplify | tac
+}
+
+GET() {
+ curl -sS -b 'LEOABTEST=T; browser=webkit%3B5%3Bajax' \
+ "https://dict.leo.org/dictQuery/m-vocab/$langlang/query.xml?tolerMode=nof&lp=$langlang&lang=$lang&rmWords=off&rmSearch=on&search=$search&searchLoc=0&resultOrder=basic&multiwordShowSingle=on"
+}
+
+simplify() {
+ sed '
+ s|<repr>|\nREPR: |g
+ s|</repr>|\n|g
+ ' | grep ^REPR |
+ sed '
+ s/^REPR: //
+ 1~2{s/$//}
+ 2~2{s/$//}
+ ' |
+ tr -d \\n |
+ sed '
+ s// - /g
+ s//\n/g
+
+ #q
+
+ s/&#8660;/⇔/g
+ s/&#160;/ /g; # &nbsp;
+ s/ */ /g
+
+ # <!-- undefined_translation: en:pl_ext -->
+ s/ *<!--[^>]*-->//g
+
+ s|<i> *|/|g
+ s| *</i>|/|g
+
+ s:<sup>1</sup>:¹:g; s:<sup>2</sup>:²:g; s:<sup>3</sup>:³:g;
+ s:<sup>:^(:g
+ s:</sup>:):g
+
+ s:<sub>0</sub>:₀:g;
+ s:<sub>1</sub>:₁:g; s:<sub>2</sub>:₂:g; s:<sub>3</sub>:₃:g;
+ s:<sub>4</sub>:₄:g; s:<sub>5</sub>:₅:g; s:<sub>6</sub>:₆:g;
+ s:<sub>7</sub>:₇:g; s:<sub>8</sub>:₈:g; s:<sub>9</sub>:₉:g;
+ s:<sub>:_(:g
+ s:</sub>:):g
+
+ s:<b> *::g
+ s: *</b>::g
+
+ s|<small> *||g
+ s| *</small>||g
+
+ '
+}
+
+main "$@"