Receiving notifications for new stackoverflow c++ questions


Just created a quick perl script for reading the c++ question rss feed and used notify-send to get the notifications in the desktop.
You need libnotify-bin and notification-daemon installed in your debian/ubuntu

#!/usr/bin/perl
use warnings;
use strict;
use LWP::Simple;

my $url="http://stackoverflow.com/feeds/tag/c%2b%2b";
my $max = 5;

my %newshash;
while(1){

    my @news;
    my @titles;
    my @urls;

    my $feed = get $url;
    if(not $feed){
        my $exec = "notify-send -t 10000 \"Stackoverflow C++\" \"Can't reach $url\"";
        system($exec);
        sleep(600);
        next;
    }
    @urls = $feed =~ m/<id>(.+)<\/id>/g;
    @titles = $feed =~ m/<title type="text">(.+)<\/title>/g;
    for( my $i=0; $i<(scalar @titles) ; $i++){
        push(@news,[$titles[$i],$urls[$i]]);
    }
    shift(@news);

    my $printed = 0;
    for my $new (@news){
        my($id) = $new->[1] =~ m/questions\/([0-9]+)\// or print "Faulty id in $new->[1]";

        if( not exists($newshash{$id})){
            $newshash{$id} = $new-[1];
            if($printed<$max){
                my $exec = "notify-send -t 10000 'Stackoverflow C++'  '<a href=\"".$new->[1]."\">".$new->[0]."</a>'";
                system($exec);
                print $new->[0] . "\n";
            }
            $printed++;
       }
    }
    sleep 300;
}

One Response to Receiving notifications for new stackoverflow c++ questions

  1. JammyZ says:

    Cracker!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: