se 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use LWP::Simple;
  5. use Getopt::Long;
  6. use Pod::Usage;
  7. use File::Basename;
  8. binmode STDOUT, ":encoding(UTF-8)";
  9. sub usage;
  10. my $direction = 'encz.en';
  11. my $lines = 25;
  12. my $max_lines = 50;
  13. my $long = 0;
  14. my $man = 0;
  15. my $help = 0;
  16. my $host = 'www.slovnik.cz';
  17. GetOptions(
  18. 'long|l' => \$long,
  19. 'lines|n=i' => \$lines,
  20. 'direction|d=s' => \$direction,
  21. 'help|?|h' => \$help,
  22. 'man' => \$man
  23. ) or pod2usage(2);
  24. pod2usage(1) if $help;
  25. pod2usage(-exitstatus => 0, -verbose => 2) if $man;
  26. $lines = $max_lines if $long;
  27. my $word = shift or usage;
  28. my $query = sprintf(
  29. '/bin/mld.fpl?vcb=%s&dictdir=%s&lines=%s',
  30. $word,
  31. $direction,
  32. $lines
  33. );
  34. my $url = "http://$host$query";
  35. my @lines = split m|\n|, get($url);
  36. @lines = grep m|class="pair"|, @lines;
  37. foreach (@lines) {
  38. s/<.*?>//g;
  39. print;
  40. print "\n";
  41. }
  42. sub usage {
  43. printf STDERR "usage: %s [options] word\n", basename($0); exit 1;
  44. }
  45. __END__
  46. =head1 NAME
  47. se - Translate en-* to/from cs-CZ and many other languages using
  48. www.slovnik.cz service
  49. =head1 SYNOPSIS
  50. B<se> [I<OPTIONS>] I<WORD>
  51. =head1 DESCRIPTION
  52. B<se> will take English word, compose a query to dictionary service at
  53. http://www.slovnik.cz/, fetch the English - Czech pairs and display them
  54. to stdout.
  55. Although English to Czech is default, using B<--direction> parameter
  56. you can translate Czech to English or even between Czech and many other
  57. languages.
  58. For I<WORD> with diacritics, you can provide it
  59. =over 8
  60. =item * directly if your terminal supports it (tested with few Czech words
  61. on Debian 6.0 with urxvt)
  62. =item * directly with diacritics stripped, or
  63. =item * using special notation described here:
  64. http://www.slovnik.cz/alternative_chars.html
  65. Few simple examples:
  66. =over 8
  67. =item * C<c<ert/ik> - c with caron, i with acute
  68. =item * C<pu@da> -- u with ring above
  69. =item * C<Bu:ro> -- u with diaeresis
  70. =item * C<c\eramique> -- e with grave
  71. =item * C<valdepen~as> -- n with tilde
  72. =back
  73. =back
  74. =head1 OPTIONS
  75. =over 8
  76. =item B<-d> I<DIR>, B<--direction=>I<DIR>
  77. Direction of translation. Aside from the default encz.en, it can be
  78. one of following:
  79. encz.en, encz.cz, gecz.ge, gecz.cz, frcz.fr, frcz.cz,
  80. itcz.it, itcz.cz, spcz.sp, spcz.cz, rucz.ru, rucz.cz,
  81. lacz.la, lacz.cz, eocz.eo, eocz.cz, eosk.eo, eosk.sk,
  82. plcz.pl, plcz.cz
  83. =item B<-l> I<LINES>, B<--lines=>I<LINES>
  84. Number of lines fetched fronm the service and displayed to stdout.
  85. Default is 25, but since www.slovnik.cz provides simplistic interface
  86. with only one term per line, so for words with lot of synonyms, you
  87. might want to specify more.
  88. =item B<--help>
  89. Prints a brief help message and exits.
  90. =item B<--man>
  91. Prints the manual page and exits.
  92. =back
  93. =head1 THANKS
  94. Big thanks to Martin Vi/t, LangSoft and everybody who contributed to
  95. existence of this awesome service.
  96. http://www.slovnik.cz/about.html
  97. I have been using www.slovnik.cz for B<many years> now, mostly as a custom
  98. search in Opera, so I grew so accustomed to its reliability and simple
  99. interface that I can't even imagine using anything else. (Or remember
  100. I ever had). I could never repay.
  101. =head1 AUTHOR
  102. ...of this scriptie: Alois Mahdal at zxcvb tec<ka cz
  103. =cut