new-words

changeset 30:07d89c2505e7

lingvo en->ru by Andrii Grytsenko
author Igor Chubin <igor@chub.in>
date Sun Jul 04 12:24:01 2010 +0200 (2010-07-04)
parents c631833fa2be
children 48ca8248e9cc
files en.sh lingvo-en-ru.pl
line diff
     1.1 --- a/en.sh	Mon Jun 21 19:46:58 2010 +0300
     1.2 +++ b/en.sh	Sun Jul 04 12:24:01 2010 +0200
     1.3 @@ -10,7 +10,8 @@
     1.4  case $myname in
     1.5    "de") DICT_NAME=deu-eng ; 
     1.6          DICTD_SERVER_ARGS='' 
     1.7 -        dict $DICTD_SERVER_ARGS -d "$DICT_NAME" "$@"
     1.8 +        #dict $DICTD_SERVER_ARGS -d "$DICT_NAME" "$@"
     1.9 +        sdcv -n "$@"
    1.10          ;;
    1.11    "pl") DICT_NAME=slovnyk_pl-ru 
    1.12          dict $DICTD_SERVER_ARGS -d "$DICT_NAME" "$@"
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/lingvo-en-ru.pl	Sun Jul 04 12:24:01 2010 +0200
     2.3 @@ -0,0 +1,49 @@
     2.4 +#!/usr/bin/perl
     2.5 +
     2.6 +# written by Andrii Grytsenko, 2010
     2.7 +
     2.8 +use Locale::Recode;
     2.9 +use LWP::UserAgent;
    2.10 +use strict;
    2.11 +
    2.12 +
    2.13 +sub parse_html {
    2.14 +    my $text = shift;
    2.15 +    my $result ;
    2.16 +    $text =~ s/></>\n</g;
    2.17 +    foreach my $line (split(/\n/,$text)){
    2.18 +	$result .= $line."\n" if ( $line =~ /span class=.translation/ or $line =~ /lol-dict-name/ or 
    2.19 +				   $line =~ /span class=.Abbrev./ or $line =~ /span class=.comment./);
    2.20 +    }
    2.21 +    return $result;
    2.22 +}
    2.23 +
    2.24 +sub print_html {
    2.25 +    my $text = shift; 
    2.26 +    my $class = 0;
    2.27 +    foreach my $line (split(/\n/,$text)){
    2.28 +	$line =~ s/<[^>]+>//g ; #delete all html tags
    2.29 +	print "$line\n";
    2.30 +    }
    2.31 +}
    2.32 +
    2.33 +
    2.34 +my $cd = Locale::Recode->new (from => 'UTF-8', to => 'koi8-r');
    2.35 +die $cd->getError if $cd->getError;
    2.36 +my $ua = LWP::UserAgent->new;
    2.37 +$ua->agent("Firefox/0.1 ");
    2.38 +
    2.39 +my $word = $ARGV[0];
    2.40 +my $req = HTTP::Request->new(GET => "http://lingvo.abbyyonline.com/en/en-ru/$word");
    2.41 +
    2.42 +my $res = $ua->request($req);
    2.43 +
    2.44 +if ($res->is_success) {
    2.45 +    my $text = $res->content;
    2.46 +    $cd->recode($text); # change code encoding from UTF-8 to koi8-ru
    2.47 +    print "Translate for word $word\n";
    2.48 +    $text = parse_html($text);
    2.49 +    print_html($text);
    2.50 +} else {
    2.51 +    print $res->status_line, "\n";
    2.52 +}