Browse Source

Merge branch 'master' of github.com:AloisMahdal/minions

Alois Mahdal 11 years ago
parent
commit
246a539cf4
2 changed files with 178 additions and 2 deletions
  1. 27
    2
      README.md
  2. 151
    0
      bin/se

+ 27
- 2
README.md View File

@@ -79,6 +79,31 @@ Script to measure how long does one second take.  For those that know how long
79 79
 one second takes, it can serve as a snippet for Perl `&stamp()`.
80 80
 
81 81
 
82
+### se ###
83
+
84
+Translate to and from Czech.  Especially sweet if you need to concentrate
85
+on the work, i.e. avoid all the blinking flashing smiling Internets looks.
86
+This guy only tells you the woords.
87
+
88
+    se [options] word
89
+
90
+Throw a word at it and by default, it will throw you back few Czech
91
+translations of it, one pair per line.  Sweet.  Also supports other languages
92
+(about 10 in total).
93
+
94
+Most useful options are --lines (default is 25) and --direction which supports
95
+direction keyword in form "LNcz.cz" or "LNcz.LN", where LN is 2-letter code
96
+(**not** ISO) of the other language.
97
+
98
+Uses [www.slovnik.cz][2], so an Internet connection and [LWP::Simple][3] are
99
+needed.
100
+
101
+  [2]: http://www.slovnik.cz/
102
+  [3]: http://search.cpan.org/~gaas/libwww-perl-6.05/lib/LWP/Simple.pm
103
+
104
+Has POD doc (`se --man` or `se --help`) worth looking at.
105
+
106
+
82 107
 ### watchdump.pl ###
83 108
 
84 109
 Trivial utility that prints a text file, clears the screen and pauses for 2s
@@ -96,9 +121,9 @@ see `--usage`.
96 121
 ### pl2yml.pl, yml2pl.pl ###
97 122
 
98 123
 Simple scripts to read YAML/Perl data structure from a file and dump it in
99
-the other format to STDIN.  Uses [YAML::Tiny][2] for YAML jobs.
124
+the other format to STDIN.  Uses [YAML::Tiny][4] for YAML jobs.
100 125
 
101
-  [2]: https://metacpan.org/module/YAML::Tiny
126
+  [4]: https://metacpan.org/module/YAML::Tiny
102 127
 
103 128
 
104 129
 cgi-bin - CGI scripts

+ 151
- 0
bin/se View File

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