Hazel_perl Lapin nain
Localisation : france Nbr de messages : 9 Carottes : 5587
| Sujet: Faire causer par script (perl) Mar 25 Aoû 2009 - 14:24 | |
| action vaine s'il en est mais parions que nos lapins ne resterons pas muets: ci dessous un petit script perl pour faire parler le lapin à partir de scripts: Le retour de getprint est hideux mais c'est plus cher pour faire un retour propre, pis c'est du script hein ? - Code:
-
#!perl use strict; use LWP::Simple; use Getopt::Long; my $versionlevel="1.1" ;
# constants my $address='api.nabaztag.com/vl/FR/api.jsp';
# internal variable my $message='';
# defaults my $d_debug = 0; my $d_SN = ''; my $d_Token = ''; my $d_Character = ''; my $d_tts = '';
# parameters my $debug = $d_debug; my $SN = $d_SN; my $Token = $d_Token; my $Character = $d_Character; my $tts = $d_tts; my $help = ''; my $version = ''; my $tts ='';
GetOptions ("SN=s" => \$SN, "Token=s" => \$Token, "Read=s" => \$tts, "Character:s" => \$Character, "Help+" => \$help, "Version+" => \$version, "Debug+" => \$debug);
# version : die "version $versionlevel\n" if $version; # debug mode $debug=1 if ($debug>1); print "default SN : ${d_SN}\n" if $debug; print "default Token : ${d_Token}\n" if $debug; print "default Character : ${d_Character}\n" if $debug; print "default Say : ${d_tts}\n" if $debug;
# check entries : Accept only if SN, Token and tts : $help='1' if (not($SN and $Token and $tts)) ; die "usage --SN sn --Token token [--Character character] [--Debug] --Read tts | --Help| --Version \n single letter option works too\n" if ($help);
# format message entries $tts =~ y/ /+/; $SN =~ y/ //; $Token =~ y/ //; $Character =~ y/ //;
# define message $message = "sn=${SN}&token=${Token}"; $message = "${message}&voice=${Character}" if (not(not($Character))); $message = "${message}&tts=${tts}"; print "Sending request ${message}\n" if $debug;
# send message getprint("http://${address}?${message}"); | |
|