Last active
August 29, 2015 14:27
-
-
Save c6p/073d5c058980cd5d7844 to your computer and use it in GitHub Desktop.
SesliSözlük word translation, notification and flashcard reminder
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#word=`xsel -o`; | |
word='' | |
for i in "$@"; | |
do | |
word=$word" "$i; | |
done | |
html=`wget --no-cookies -q "http://www.seslisozluk.net/$word-nedir-ne-demek/" -O-`; | |
# get line numbers | |
ntr=`echo "$html" | grep -n "İngilizce - Türkçe" | sed 's,:.*,,g'`; | |
nen=`echo "$html" | grep -n "Türkçe - İngilizce" | sed 's,:.*,,g'`; | |
function get { | |
echo "$html" | sed -n "/$1/,/<\/ol>/p" | sed 's,<span.*</span>,,g' | sed 's, *<code>[^/]*</code> *,,g' | sed 's,</li><li>, / ,g' | sed -n "/<li>/,/<\/li>/p" | sed 's,.*<li>,,' | sed 's,</li>.*,,' | fold -s80; | |
} | |
# get translation | |
tr=$(get "İngilizce - Türkçe") | |
en=$(get "Türkçe - İngilizce") | |
# get first translation | |
if [ "$ntr" -a "$nen" ]; then | |
if [ "$ntr" -lt "$nen" ] | |
then | |
notify-send -u low -t 30000 " $word (English->Türkçe)" "$tr\n <b>$word (Türkçe->English)</b>\n$en"; | |
else | |
notify-send -u low -t 30000 " $word (Türkçe->English)" "$en\n <b>$word (English->Türkçe)</b>\n$tr"; | |
fi | |
# add to flashcard for review | |
flashcard insert "en-tr" "$word" "$tr" | |
flashcard insert "tr-en" "$word" "$en" | |
elif [ -n "$ntr" ]; then | |
notify-send -u low -t 20000 " $word (English->Türkçe)" "$tr"; | |
flashcard insert "en-tr" "$word" "$tr" | |
elif [ -n "$nen" ]; then | |
notify-send -u low -t 20000 " $word (Türkçe->English)" "$en"; | |
flashcard insert "tr-en" "$word" "$en" | |
else | |
notify-send -u low -t 20000 " $word " "<Çeviri Yok>"; | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment