i have no name - 2003-02-05

i've made some code to grab data from webpages and making it available in the bots. I use it for horoscope, but we can imagine meteo, news, etc, etc in our hubs that way.

here's how i do. I have a first Perl script, that cron will run every hours :

#!/bin/sh

perl /root/horoscope.pl belier > /root/.opendchub/scripts/belier.txt
perl /root/horoscope.pl taureau > /root/.opendchub/scripts/taureau.txt
perl /root/horoscope.pl gemeaux > /root/.opendchub/scripts/gemeaux.txt
perl /root/horoscope.pl cancer > /root/.opendchub/scripts/cancer.txt
perl /root/horoscope.pl lion > /root/.opendchub/scripts/lion.txt
perl /root/horoscope.pl vierge > /root/.opendchub/scripts/vierge.txt
perl /root/horoscope.pl balance > /root/.opendchub/scripts/balance.txt
perl /root/horoscope.pl scorpion > /root/.opendchub/scripts/scorpion.txt
perl /root/horoscope.pl sagittaire > /root/.opendchub/scripts/sagittaire.txt
perl /root/horoscope.pl capricorne > /root/.opendchub/scripts/capricorne.txt
perl /root/horoscope.pl verseau > /root/.opendchub/scripts/verseau.txt
perl /root/horoscope.pl poissons > /root/.opendchub/scripts/poissons.txt

Then, in my bot, there's a command, "*horoscope" followed by the name of the sign, that returns the data grabbed that way (assuming $data contains from after the "> " till before the "|" of the main chat query):

        # Horoscope.
        if(substr($data, 0, 10) eq "*horoscope") {
            $signe = substr($data, 11);
            if(($signe eq "balance") || ($signe eq "belier") || ($signe eq "cancer") || ($signe eq "capricorne") || ($signe eq "gemeaux") || ($signe eq "lion") || ($signe eq "poissons") || ($signe eq "sagittaire") || ($signe eq "scorpion")
|| ($signe eq "taureau") || ($signe eq "verseau") || ($signe eq "vierge")) {
                my(@horoscope) = `more /root/.opendchub/scripts/$signe.txt`;
                $message = substr($horoscope[3], 0, -2);
                odch::data_to_user($user, "\$To: $user From: $botname \$<$botnam
e> $message|");
                $message = substr($horoscope[4], 0, -2);
                odch::data_to_user($user, "\$To: $user From: $botname \$<$botnam
e> $message|");
            } else {
                odch::data_to_user($user, "<$botname> $signe n'est pas un signe
astrologique occidental.|");
            }
        }

What it does : The first script (that is a stand alone script, not part of any bot) will get the horoscope from a website for every sign, at every hours (thanx cron), putting the result in text files. The second part (that is part of the bot this time), will read on the fly the created text files, and send the result as private messages to the user that asked it.

Arf, by re-reading i saw i forgot the horoscope.pl script. so here it is :

#!/usr/local/bin/perl

$Date = 0;
$Horoscope = 0;
if($ARGV[0] eq "--help") {
    print "traduis.pl version 0.1\r\nUsage : horoscope.pl signe. Utilisez les redirections (>Fichier) pour renvoyer la sortie dans un fichier.\r\n"
;
} else {
    my(@tmpData) = `lynx -source \&quot;http://chaines.free.fr/horoscope/daily/$ARGV[0].html
\&quot;`;
    for($i=0; $i<@tmpData; $i++) {
        my($Data) = $tmpData[$i];
        if($Data =~ /<b>HOROSCOPE/) {
            $Date = $i + 1;
        }
        if($Data =~ /colspan=\&quot;2\&quot;><br>/) {
            $Horoscope = $i + 2;
        }
    }
    $Resultat = substr($tmpData[$Date], 0, index($tmpData[$Date], "<"))."\r\n".$tmpData
[$Horoscope];
    print $Resultat;
}

Davidator