working in "production":
#!/usr/bin/perl
use lib qw( /mnt/web4/10/47/51683347/htdocs/lib/site_perl/5.8.5 );
use warnings;
use strict;
use DBI;
use WWW::Mechanize;
use XML::Simple;
my ($sth, $dbh, $xml);
my $messages = [];
my $mech = WWW::Mechanize->new();
while (1)
{
my $resp = $mech->get( 'http://www.perlmonks.org/index.pl?node_id=
+207304' );
if ( $resp->is_success )
{
my $xml = $resp->content;
my $jatter = XMLin( $xml, ForceArray => ['message'] );
if ( $jatter->{info}->{count} > 0 )
{
print STDERR "adding ", scalar @{$jatter->{message}}, "\n"
+;
unless ( $dbh )
{
$dbh = DBI->connect("DBI:mysql:database=DB354211;host=
+rdbms.strato.de", 'U354211', 'pw354211');
$sth = $dbh->prepare('INSERT INTO pmf_jatterboxx (user
+_id, author, epoch, message_id, message) VALUES (?, ?, ?, ?, ?)');
}
for ( @{$jatter->{message}} )
{
$sth->execute( $_->{user_id}, $_->{author}, $_->{epoch
+}, $_->{message_id}, $_->{text} );
}
}
else
{
print STDERR "snooze\n";
}
}
sleep(5);
}
note: It is not obvious, but the chatterbox feed somehow notices the caller and returns only the chat-lines that are new; even without passing a date flage or something. I am curious how that works.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.