Posts Tagged ‘perl’

Status RSS plugin for pidgin

As a pidgin user I am used at not expecting many fancy things but one of the features I’ve wished for some time is a plugin which updates the status automatically to the last entry in a RSS feed. As an example I’d like to update the status to the last post on my blog. So, even if I don’t like perl too much here is a simple plugin which does just that. It’s inspirationaly called: Status RSS :)




apt-get install awstats

copy configuration files and cached data (old statistics) from old machine (the
cached data will have to be copied once again exactly before moving to

mkdir /var/cache/awstats
ln -s /usr/share/doc/awstats/examples/
apt-get install libgeo-ipfree-perl libgeo-ip-perl geoip-bin
#(required for the geoip plugin for awstats)

Build the stats files using:

$AWSTATS -update -dir=/data/www/data/analyze/awstats -awstatsprog=$AWSTATS

Not so simple

At first everything seemed ok and I was even dumb enough to not check the results in detail but after a while I realized they did not worked:

Error Opening file GeoIP.dat....Can't call method "country_code_by_addr" on an undefined value at /usr/share/awstats/plugins/ line 96, <LOG> line 2.

I decided to do a small program of my own to check


use Geo::IP;
my $gi = Geo::IP->open(“/usr/share/GeoIP/GeoIP.dat”, GEOIP_STANDARD);
print $gi->country_code_by_addr(“”);

This worked so finally I modified the /usr/share/awstats/plugins/ file:

if (! $datafile) { $datafile="/usr/share/GeoIP/GeoIP.dat"; }
if (! $datafile) { $datafile="GeoIP.dat"; }

Koha AMS integration

This describes the modifications which have been done to a standard Koha 2.2.5 installation in order to be provide a basic AMS integration for IMAR: “Simion Stoilow” Institute of Mathematics of the Romanian Academy library system.

AMS integration

One of the requirements of the customization was to allow a basic AMS integration. For each ISBN code the corresponding AMS code had to be found using a crawler.

This was achieved by a value_builder plugin which consists of 3 parts:


use strict;
use C4::Auth;
use CGI;
use C4::Context;
use HTML::Template;
use C4::Search;
use C4::Output;
plugin_parameters : other parameters added when the plugin is called by the dopop function
sub plugin_parameters {
    my ($dbh,$record,$tagslib,$i,$tabloop) = @_;
    return "";
sub plugin_javascript {
    my ($dbh,$record,$tagslib,$field_number,$tabloop) = @_;
    my $function_name= "ams".(int(rand(100000))+1);
    my $res="
function Focus$function_name(subfield_managed) {
return 1;
function Blur$function_name(subfield_managed) {
return 1;
function Clic$function_name(fi) {
    var isbn = \"\";
    var isbncnt = 0;
    for (i=0 ; i<document.forms['f'].field_value.length ; i++) {
        if (document.forms['f'].kohafield[i].value == \"biblioitems.isbn\"){
            if(document.forms['f'].field_value[i].value.length>0) {
                isbn = document.forms['f'].field_value[i].value;
                if(isbn.length > 0){
                     //document.f.field_value[i].value = 'test';
           \"../\"+fi+\"&isbn=\"+isbn,\"field_ams_\" + isbncnt,'width=500,height=400,toolbar=false,scrollbars=yes');
                isbncnt = isbncnt + 1;
        alert(\"Please fill the ISBN field first\");
    return ($function_name,$res);
sub plugin {
    my ($input) = @_;
    my %env;
    my $index= $input->param('index');
    my $isbn = $input->param('isbn');
    if ($isbn =~ /([0-9X]{10,13})/i){
	$isbn = $1;
	print "ISBN:".$isbn." does not match format\n";
    my ($template, $loggedinuser, $cookie)
	= get_template_and_user({template_name => "value_builder/usmarc_field_ams.tmpl",
                             query => $input,
                             type => "intranet",
                             authnotrequired => 0,
			     flagsrequired => {editcatalogue => 1},
                             debug => 1,
    if(eval {require Business::ISBN}){
	require Business::ISBN;
	my $isbn_object = Business::ISBN->new($isbn);
	if($isbn_object->is_valid() == Business::ISBN::GOOD_ISBN()){
	    $isbn = $isbn_object->as_string;
    my $amsCodes = getAMSCodes($isbn);
    $template->param(index=> $index, isbn => $isbn, amsCodes => $amsCodes);
    print $input->header(-cookie => $cookie),$template->output;
sub getAMSCodes{
    my $amsServer = "";
    if(eval {require Net::HTTP}){
	require Net::HTTP;
	my ($isbn)=@_;
	#my $query = "/msnmain?preferred_language=en&pg3=ALLF&s3=".$isbn."&l=20&reference_lists=show&simple_headlines=full&contributed_items=show&redirect=Providence%2C+RI+USA&Submit=Start+Search&fn=130&form=basicsearch";
	my $query = "/mathscinet/search/publdoc.html?arg3=&co4=AND&co5=AND&co6=AND&co7=AND&dr=all&pg4=AUCN&pg5=TI&pg6=PC&pg7=ALLF&pg8=ET&r=1&s4=&s5=&s6=&s7=".$isbn."&s8=All&yearRangeFirst=&yearRangeSecond=&yrop=eq";
	my $s = Net::HTTP->new(Host => $amsServer) || die $@;
	$s->write_request(GET => $query, 'User-Agent' => "Mozilla/5.0");
	my($code, $mess, %h) = $s->read_response_headers;
	my $buf;
	while (1) {
	    my $tbuf;
	    my $n = $s->read_entity_body($tbuf, 1024);
	    die "read failed: $!" unless defined $n;
	    last unless $n;
	    $buf = $buf.$tbuf;
        #TODO: check for no results
	#if($buf =~ /<a href=\".*\/msnmain\?fn=705[^>]+>([^<]+)<\/a><\/div>/i) {
	if($buf =~ /<a href="\/mathscinet\/search\/mscdoc.html\?code=[^>]+>([^<]+)<\/a>/){
	    print $isbn." AMS codes found ".$1;
	    return $1;
    return "";

The usmarc_field_ams.tmpl

<!-- TMPL_INCLUDE NAME="" -->AMS category type search<!-- TMPL_VAR name="biblionumber" --><!-- TMPL_INCLUDE NAME="" -->
<div id="main-compact">
	<h1>AMS category search for ISBN<!-- TMPL_VAR name="isbn" --></h1>
<form name="f_pop">
	  <label class="labelsubfield">&nbsp;&nbsp;ISBN:</label><input type="text" size="30" name="isbn" value="<!-- TMPL_VAR name="isbn" -->"/>
<input type="submit" value="Search again" class="submit"/></br>
	  <label class="labelsubfield">Result:</label><input type="text" size="30" name="f1" value="<!-- TMPL_VAR name="amsCodes" -->"/>
<input type="button" value="Fill and close" onclick="javascript:putBack();" class="submit"/>
<input type="hidden" name="plugin_name" value=""/>
<input type="hidden" name="index" value="<!-- TMPL_VAR name="index" -->"/>
<script language="JavaScript" type="text/javascript">
        function putBack() {
                opener.document.f.field_value[<!-- TMPL_VAR name="index" -->].value= document.f_pop.f1.value;
                return false;