Article View: es.comp.os.linux.programacion
Article #16758Re: Ayuda del algun guru del Python ese o me paso al Perl :)
From: batsman batsman
Date: Mon, 27 Mar 2000 00:00
Date: Mon, 27 Mar 2000 00:00
202 lines
7385 bytes
7385 bytes
-----BEGIN PGP SIGNED MESSAGE-----
>>>> El Thu, 23 Mar 2000 13:38:19 +0100, un alien�gena
>>>> intent� hacerse pasar por *puntero_loko,
>>>> y escribi� en es.comp.os.linux.programacion:
>batsman dijo sobre Re: Ayuda del algun guru del Python ese o me paso al Perl :),
>en fecha: Wed, 22 Mar 2000 21:43:21 GMT
>Muy buena idea, de todos modos, �no hay otra p�gina que permita enviar
>sms o m�viles de todas las compa��as? Puede que si encontramos otra no
>sean tan retorcidos. Por otro lado creo que tiene m�s gracia si se puede
>ejecutar desde la l�nea de comandos que desde un formulario, manteniendo
>un archivo de alias de tel�fonos y nombres �no?
Estoy haci�ndolo en un p�gina de sourceforge, cuando est� acabado ya os dir�
cual :-)
Por el momento aqu� va la �ltima versi�n del script de env�o por Terra
(FUNCIONA :-)
- ---------------------- CORTAR AQUI (INICIO) ------------------------
#!/usr/bin/perl
# Copyright � 2000 batsman
# bla bla GPL bla bla
use CGI;
use Text::Wrap qw(wrap $columns);
use LWP::UserAgent;
use HTTP::Request::Common qw(POST GET);
local $debug = 1;
sub ajustar_fecha()
{
##my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = @_;
## 0 1 2 3 4 5 6 7 8
$_[5] = $_[5]+1900;
$_[4] = $_[4]+1;
$_[4] = "0" . "$_[4]" if ($_[4]<10);
$_[3] = "0" . "$_[3]" if ($_[3]<10);
$_[2] = "0" . "$_[2]" if ($_[2]<10);
$_[1] = "0" . "$_[1]" if ($_[1]<10);
$_[0] = "0" . "$_[0]" if ($_[0]<10);
}
sub enviar_mensaje
{
my ($linea, $telefono,$repeat) = @_;
my $remote;
if ($repeat == 0) {
print "Error al enviar el mensaje: $linea<br>" if ($debug);
return;
}
my $ua = new LWP::UserAgent;
$ua->agent("Mozilla/5.0 " . $ua->agent);
# $ua->proxy("http", "http://localhost:8080/");
# Create a request
my $seconds = time();
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($seconds);
&ajustar_fecha ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
#my $fecha = "{ts '$year-$mon-$mday $hour:$min:$sec'}";
my $cookie_monster = GET 'http://www.terra.es/sms/';
my $res;
print "<b>Obteniendo c�digo...</b><br>" if ($debug);
my $i = 0;
do {
$i++;
$res = $ua->request($cookie_monster);
} while (!$res->is_success && $i<10);
my @parts = split /\n/, $res->headers_as_string();
my @cookies;
foreach( @parts ) {
## print "Analizando l�nea $_\n";
if ( /^Set-Cookie:/ ) {
s/^Set-Cookie: //;
my @tmp = split /\;/ , $_;
## print "Insertando l�nea $tmp[0]\n";
push @cookies, $tmp[0];
}
}
print "<b>C�digo obtenido.</b><br>" if ($debug);
my $req = POST 'http://www.terra.es/sms/envio.cfm', [ telefono => $telefono,
fecha => "CHANGEME",
mensaje => $linea];
my $cfecha = "%7Bts+%27$year%2D$mon%2D$mday+$hour%3A$min%3A$sec%27%7C";
$req->header ( Referer => "http://www.terra.es/sms/" );
$req->header ( Cookie => "$cookies[0]; $cookies[1]");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($seconds+36000);
&ajustar_fecha ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
$cfecha = "%7Bts+%27$year%2D$mon%2D$mday+$hour%3A$min%3A$sec%27%7D";
${$req->content_ref} =~ s/CHANGEME/$cfecha/g;
# Pass request to the user agent and get a response back
# print "\n\nEnviando:" . $req->as_string() . "\n\n";
$res = $ua->request($req);
# Check the outcome of the response
if ($res->content =~ /correctamente/) {
print "Mensaje enviado correctamente<br>" if ($debug);
return 1;
} elsif ($repeat > 1) {
print "Error al enviar mensaje. Reintentando<br>" if ($debug);
my $i;
for ($i=0; $i<3; $i++) {
return 1 if (&enviar_mensaje($linea,$telefono,1) == 1);
print "Reintentando env�o<br>" if ($debug);
}
sleep(1);
return &enviar_mensaje($linea,$telefono,$repeat-1);
}
print ( "Error al enviar el mensaje: $linea <br>" ) if ($debug);
return 0;
}
$query = new CGI;
my $telefono = $query->param('telefono');
my $mensaje = $query->param('mensaje');
print "Content-Type: text/html\n\n";
$columns = 100;
my $linea = wrap ("","",$mensaje);
my @lineas = split(/\n/,$linea);
my $numlineas = @lineas;
$| = 1; ## turn auto-flush on
print "<html><head><title>Env�o de mensaje a m�vil</title></head>";
print "<body>";
print "<h3>Telefono</h3> $telefono" if ($debug);
print "<h3>Mensaje</h3> $mensaje" if ($debug);
print "<h1>Mensaje enviado</h1>";
print "El mensaje ha sido fragmentado en $numlineas paquetes."
if ($numlineas > 1);
print "<h1>Mensaje enviado</h1>El mensaje no ha sido fragmentado."
if ($numlineas == 1);
print "<hr>";
sleep(1);
if (!$debug) {
print "</body></html>";
close(STDOUT);
};
sub espera
{
my $tiempo=5;
print "Esperando $tiempo segundos<br>" if ($debug);
sleep($tiempo); ## wait 65 seconds after each message part
}
for ($i=1; $i<$numlineas+1; $i++) {
&espera() if ($i>1);
&enviar_mensaje("$lineas[$i-1]\n$i/$numlineas\n(c) 2000 MFP",$telefono,10);
}
if ($debug) {
print "<hr>";
print "</body></html>";
close(STDOUT);
};
- ---------------------- CORTAR AQUI (FIN) ---------------------------
- --
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
________________________________________________________________
|Visit | http://www.geocities.com/SiliconValley/Vista/2075 |
|Linux | http://www.geocities.com/SiliconValley/Vista/4289 |
----------------------------------------------------------------
Real email: batsman dot geo at yahoo dot com
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
Comment: Public key via email: send mail with Subject: [PGPKEY]
iQEVAwUBON+1Vr0Y27yr0iefAQH8lAf+MnmNLpO9yFn4Ew49Sazl/56XvY7Pd/0T
l/jZ3Vq3FGo5MDWuYyyFH7ZTOtB6KRQHBp2J86LK7fMjwOqVbLxEwqpantCC6t8c
JTUU84nHOOYprKPhRu5/X0qKDcbgoINYX/f8U01cGz6Oh7BNrWMXD8wsq9wB+C/t
PZKbIJkWuKjFZUjni2MdqD2hnrj6JjTiZhxNlteyUlLB9DQlTdRGXqO+DlzH5KMY
+e5KzNcdmEK2Z71o56yYbELhKKH3pHEiknQ8nkttsS/qYj2oOZGN1u1MdzJLd9yJ
bd5usqjid0SuZh9Ssj7p5SEsGJ/cPqC4x7eoMKRlIngBpIT2dSceXA==
=CHuV
-----END PGP SIGNATURE-----
Technical Details
Message-ID:
<rgcob8.lq1.ln@simpsons4ever>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<slrn8dfrg7.79g.jajs@Pascual.es> <uhfbb8.1h1.ln@simpsons4ever> <slrn8dk41r.185.jajs@Pascual.es>Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII X-Google-Thread: f86c8,fcc95392be363063 X-Google-Attributes: gidf86c8,public From: batsman@simpsons4ever. (batsman) Subject: Re: Ayuda del algun guru del Python ese o me paso al Perl :) Date: 2000/03/27 Message-ID: <rgcob8.lq1.ln@simpsons4ever> X-Deja-AN: 603055573 Content-Transfer-Encoding: 8bit References: <slrn8dfrg7.79g.jajs@Pascual.es> <uhfbb8.1h1.ln@simpsons4ever> <slrn8dk41r.185.jajs@Pascual.es> Content-Type: text/plain; charset=iso-8859-1 X-Complaints-To: abuse@news.wanadoo.es X-Trace: m2newsread.uni2.es 954182539 62.36.41.102 (Mon, 27 Mar 2000 20:42:19 MET DST) Organization: Wanadoo Usenet News - Visita http://www.wanadoo.es/ Mime-Version: 1.0 Reply-To: see_signature-mira_firma NNTP-Posting-Date: Mon, 27 Mar 2000 20:42:19 MET DST Newsgroups: es.comp.os.linux.programacion