Skip to content

Instantly share code, notes, and snippets.

@adamvr
Created June 11, 2012 11:52
Show Gist options
  • Select an option

  • Save adamvr/2909738 to your computer and use it in GitHub Desktop.

Select an option

Save adamvr/2909738 to your computer and use it in GitHub Desktop.
Script for scraping dict.cc for conjugations
#!/bin/sh
p=$2;
t=$3;
word=$1;
case "$2" in
'ich')
p=1
;;
'du')
p=2
;;
'er')
p=2
;;
'sie')
p=2
;;
'es')
p=2
;;
'wir')
p=3
;;
'ihr')
p=4
;;
'Sie')
p=5
;;
'all')
p='all'
;;
*)
p=-1
;;
esac
case "$3" in
'present')
t=1
;;
'praesens')
t=1;
;;
'präsens')
t=1;
;;
'imperfekt')
t=2;
;;
'konjunctivI')
t=3;
;;
'konjunctivII')
t=4;
;;
*)
p=-1
;;
esac
[ $p == -1 ] && [ $t == -1 ] && exit 1
curl http://www.dict.cc/deutsch/${word}.html 2>/dev/null |
xmllint --html - 2>/dev/null |
awk "
/BEGIN/ { inVerbs = 0; person = 0; tense = 0 }
/Konjugation des Verbs/ { inVerbs = 1; person = -1 }
/^<tr/ {
if (inVerbs) {
person++;
tense = -1;
}
}
/^<td/ {
if (person > 0)
tense++;
}
/<\/table>/ {
if (inVerbs)
inVerbs = 0;
}
inVerbs && ($p == all || $p == person) && $t == tense { print }
" |
sed 's/<[^<]*>//g;/^$/d'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment