Friday, March 19, 2010
Wednesday, May 30, 2007
IRC RSS Aggregator Bot
I wanted a IRC RSS Aggregator bot and did not find any on the allmighty web, so I had to create my own. It is written in Perl and uses POE::Component::IRC and POE::Component::RSSAggregator. Here is the code:
The config file for the rss should look like this:
#!/usr/bin/perl
use strict;
use warnings;
use POE;
use POE qw(Component::IRC);
use POE::Component::RSSAggregator;
$|++;
# Config.
my $rss_config = 'rss.cfg';
my $rss_config_saved = 'rssc.cfg';
my $nick = 'rssbot';
my $server = 'irc.myircnet.net';
my $port = 6667;
my $name = 'IRC RSS aggregator bot, by septic';
my @channels = ();
my @feeds = ();
my %globalheadline;
my %counter;
open(CONFIG, "<$rss_config");
while(<CONFIG>){
next if(/^#/);
$_ =~ s/\n//;
my @vals = split / /, $_;
push @feeds, { url => $vals[0],
name => $vals[1],
delay => $vals[2],
};
}
close(CONFIG);
foreach(@feeds) {
print $_->{url}." ";
print $_->{name}." ";
print $_->{delay}."\n";
}
my $irc = POE::Component::IRC->spawn(
nick => $nick,
server => $server,
port => $port,
ircname => $name,
) or die "Oh noooo! $!";
POE::Session->create(
package_states => [
'main' => [ qw(_default _start irc_001 irc_public irc_msg) ],
],
heap => { irc => $irc },
);
POE::Session->create(
inline_states => {
_start => \&init_session,
handle_feed => \&handle_feed,
},
);
$poe_kernel->run();
exit 0;
sub init_session {
my ( $kernel, $heap, $session ) = @_[ KERNEL, HEAP, SESSION ];
$heap->{rssagg} = POE::Component::RSSAggregator->new(
alias => 'rssagg',
debug => 1,
callback => $session->postback("handle_feed"),
tmpdir => '/tmp', # optional caching
);
$kernel->post( 'rssagg', 'add_feed', $_ ) for @feeds;
}
sub handle_feed {
my ( $kernel, $feed ) = ( $_[KERNEL], $_[ARG1]->[0] );
for my $headline ( $feed->late_breaking_news ) {
my ($name,$feedname) = split /:/,$feed->name;
if(not exists $counter{$name}) {
$counter{$name} = 0;
}
$globalheadline{$name.($counter{$name}%5)} = $headline;
$irc->yield( privmsg => $name => ($counter{$name}%5)." ".$feedname.': '.$headline->headline);
$counter{$name} = $counter{$name} + 1;
}
}
#IRC
sub _start {
my ($kernel,$heap) = @_[KERNEL,HEAP];
# We get the session ID of the component from the object
# and register and connect to the specified server.
my $irc_session = $heap->{irc}->session_id();
$kernel->post( $irc_session => register => 'all' );
$kernel->post( $irc_session => connect => { } );
undef;
}
sub irc_001 {
my ($kernel,$sender) = @_[KERNEL,SENDER];
# Get the component's object at any time by accessing the heap of
# the SENDER
my $poco_object = $sender->get_heap();
print "Connected to ", $poco_object->server_name(), "\n";
# In any irc_* events SENDER will be the PoCo-IRC session
$kernel->post( $sender => join => $_ ) for @channels;
undef;
}
sub irc_public {
my ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2];
my $nick = ( split /!/, $who )[0];
my $channel = $where->[0];
if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
#$rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
#$kernel->post( $sender => privmsg => $channel => "$nick: $rot13" );
#$irc->yield( privmsg => $nick => $rot13);
}
undef;
}
sub irc_msg {
my ($kernel,$sender,$who,$where,$what) = @_[KERNEL,SENDER,ARG0,ARG1,ARG2];
my $nick = ( split /!/, $who )[0];
print "$nick: $what\n";
if(my ($val) = $what =~ /^info (\d)/) {
if(exists $globalheadline{$nick.$val}){
$irc->yield( privmsg => $nick => $globalheadline{$nick.$val}->headline);
$irc->yield( privmsg => $nick => $globalheadline{$nick.$val}->description);
$irc->yield( privmsg => $nick => $globalheadline{$nick.$val}->url);
} else {
$irc->yield( privmsg => $nick => "There is no information about $val.");
}
} elsif(my ($val) = $what =~ /^add (.+)/) {
my @thing = split / /,$val;
if(@thing != 3) {
$irc->yield( privmsg => $nick => 'add <url> <desc> <delay>');
} else {
if ($thing[0] !~ /http:\/\/[\/\w\s\d\.]*/i) {
$irc->yield( privmsg => $nick => 'Invalid URL');
} elsif (($thing[2] !~ /\d/) && ($thing[2] > 60)) {
$irc->yield( privmsg => $nick => 'Bad delay, should more than 60');
} else {
$irc->yield( privmsg => $nick => "OK $thing[0] $thing[1] $thing[2]");
my $mojt = { url => $thing[0],
name => $nick.":".$thing[1],
delay => $thing[2],
};
push @feeds, $mojt;
$kernel->post( 'rssagg', 'add_feed', $mojt );
open(CONFIG, ">$rss_config_saved");
foreach(@feeds){
print CONFIG $_->{url}." ";
print CONFIG $_->{name}." ";
print CONFIG $_->{delay}."\n";
}
close(CONFIG);
}
}
} elsif($what =~ /^help/) {
$irc->yield( privmsg => $nick => "This is the rss aggregator bot");
$irc->yield( privmsg => $nick => "Add a feed");
$irc->yield( privmsg => $nick => "add <url> <desc> <delay>");
$irc->yield( privmsg => $nick => " ");
$irc->yield( privmsg => $nick => "Information about a post");
$irc->yield( privmsg => $nick => "info <id>");
} else {
$irc->yield( privmsg => $nick => 'Write "help" if you want help.');
}
undef;
}
# We registered for all events, this will produce some debug info.
sub _default {
my ($event, $args) = @_[ARG0 .. $#_];
my @output = ( "$event: " );
foreach my $arg ( @$args ) {
if ( ref($arg) eq 'ARRAY' ) {
push( @output, "[" . join(" ,", @$arg ) . "]" );
} else {
push ( @output, "'$arg'" );
}
}
print STDOUT join ' ', @output, "\n";
return 0;
}
The config file for the rss should look like this:
#url nick:name delay
http://www.slashdot.org/slashdot.rss mynick:slashdot 300
Sunday, April 22, 2007
6581
Thursday, April 19, 2007
Wednesday, April 4, 2007
WEP is f**ked
I saw this post at /. WEP Broken Even Worse where some guys in germany have found an even faster way than the aircrack guys. Ofc it is based on aircrack, but it is much faster. With some ARP injects and some deauths a net is forced really fast. I don't want to tell if i tried it myself. If you know my curiosity you can go figure yourself!
Wednesday, March 14, 2007
Zilog Z80

Found some very nice programs for my old TI-82 that i copied to it today. I also found a guide for making your own Z80 .asm programs. The best TI source is definately www.ticalc.org.
Monday, February 19, 2007
Opera
Mouse gestures in Opera are nice. But if you dont use them they are difficult to remember.. A few is nice to know. Especially the commands you do frequently when you are surfing the big waves of the web.
Saturday, February 10, 2007
Heroes
Heroes is a great show! My friend told me about it, when so even my lab partner did i really had to check it out. In two days i've seen all the episodes that have been aired. I am totally stuck. But now I have to catch up with the programming in the operating system course. We are improving functionality in the OS emulator Nachos.
Synthesizer
Friday, February 2, 2007
slip warn

I bought a slip warner for my car the other day. Amazing what nice stuff you can find at clas ohlson. It warns when the temperature is between +3.0°C and -1.0°C, -7.0°C and -9.0°C. The most critical regions are between +1.0°C and -1.0°C, -8.0°C and -9.0°C. The lower limit warns for when the road salt has no effect.
Sunday, January 28, 2007
Yamaha SY77

I have sold my not so precious Yamaha SY77 through blocket. Quite difficult to sell stuff through an ad site like that. Difficult to hear over the phone if people are serious or not. It is rather unpleasant to send it across whole sweden too. But i think it will go well.
Wednesday, January 17, 2007
Clone
A friend of mine bought a new disk. 250 gb sata2, but he already had exactly a disk like that. He is about to build a cabinet for the old disk and use the new one in his desktop. His problem was now that he wanted an exact copy of the existing disk. He asked me how to do it. I didn't come up with any good idea how to do it in windows. Mostly because i am becoming more and more unfamiliar with that OS. I told him to boot up a linux live-cd and run the command: `cat /dev/sda > /dev/sdb`. He was a little uncertain that it would work, so he asked me to come over and help him. So I did, while his fast disks cloned themselves we ate some cake. And only after a while he rang me and said that everything went very well booting the new disk. He was happy, and I got some cake..
Monday, January 8, 2007
bZerk B104EXBB
Sony Ericsson k750i
I recently bought a used Sony Ericsson k750i that was branded Swisscom. I wanted it in swedish instead. So i asked my sisters boyfriend who is very much into mobile phones. I asked him what to to, and he gave me the software for flashing it. Really amazing stuff! I upgraded it to a w800i with only the DCU-60 cable that is included when you buy the piece of electronic. I am really impressed that it was so easy to do it myself. Of course I don't think the warranties are valid anymore. But hey! - What warranties? ;) The next step is to check out som synchronizing software for linux.
Monday, January 1, 2007
Creative Zen
Got a Creative Zen 512MB for christmas present. It seems like a good player and excellent for a linuxgeek like me. In my humble opinion the sound quality is superb. It's a little sad that it doesn't support .ogg or .flac though. But i am happy anyway.
Thursday, December 21, 2006
disks
I had a 160 GB drive in my desktop and today I moved it to my disk
server instead. It seems that it is running quite hot, 42°C, wounder if that is too much. The other drives are at 38°C and 31°C. The disk in the desktop is 35°C. I have to test and see if it works.
server instead. It seems that it is running quite hot, 42°C, wounder if that is too much. The other drives are at 38°C and 31°C. The disk in the desktop is 35°C. I have to test and see if it works.
Got quite motivated to do the lab today too. I think i will do that when i come home to my parents tomorrow. And hopefully do some ice skating too. The lab is about subdivision btw. Graphics programming..
Wednesday, December 20, 2006
Google Earth and Google Map
My girlfriend is traveling in Central America. So i decided to track her and save the coordinates. At first i only used Google Map to find the location, but i tonight i had to test Google Earth too. Mostly because i have exam tomorrow morning. Google Earth was really nice, and now i can draw a path from all the collected coordinates of my girlfriend.
Subscribe to:
Posts (Atom)

