Licence
Creative Commons License

This work by Stephane KATTOOR is licensed under a Creative Commons Attribution 3.0 Unported License.
Feeling like tipping ?
If you find this blog useful, you might consider sending a few bitcoins to support it : 1BTtsC3beGJ6ysd8DhrXjdo6jVw5WD9mvY
RSS
 
RSS Feed
Follow me !
Tech@Sakana on Facebook
Search this site

Newsletter

Get latest posts by email (No spam, only posts):

Enter your email address:

Delivered by FeedBurner

Categories
Monthly archives
May 2012
M T W T F S S
« Apr    
 123456
78910111213
14151617181920
21222324252627
28293031  

Category: Dev

All development related posts

Coding a Jabber Bot in Perl - January 22, 2006 by Stephane Kattoor

I finally got it to work and it is not so difficult with the right packages (Net::XMPP) and parameters …

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /usr/bin/perl</code>
 
use strict;
use warnings;
 
use Net::XMPP;
 
#################
# Config params #
#################
 
my $hostName = 'jaim.at';
my $portNumber = 5222;
my $componentName = 'jaim.at';
my $userName = 'totosk1008';
my $passWord = 'totosk1008';
my $resource = 'NiceLittleBot';
my $tls = 0;
my $connectionType = 'tcpip';
 
my $debugLevel = 0;
 
# Create the client
my $bot = new Net::XMPP::Client(debuglevel => $debugLevel);
 
$bot->SetCallBacks(
onconnect       => &connectedCB,       # gets called when connected
onauth          => &authedCB,          # when authenticated
ondisconnect    => &disconnectedCB,    # when disconnected
);
 
$bot->SetMessageCallBacks(                      # callback for messages
chat            => &messageCB,         # chat-type messages
);
 
$bot-&gt;Execute(                                          # entering the main loop
hostname        => $hostName,
port            => $portNumber,
tls                     => $tls,
username        => $userName,
password        => $passWord,
resource        => $resource,
register        => 0,
connectiontype  => $connectionType,
);
 
##############
# Callbacks  #
##############
 
sub messageCB {                 # call back implementing the echo
my $sid = shift;
my $msg = shift;
 
my $from = $msg->GetFrom;
my $to = $msg->GetTo;
 
my $name;
my $data;
 
print "From : ", $from, "\n",
"Subject : ", $msg->GetSubject, "\n",
$msg-&gt;GetBody, "\n";
 
$name = $msg->GetBody;
 
$data = $msg->GetBody;
 
print ">>$name<<\n";
print $data, "\n";
 
$bot->MessageSend(
to              => $from,
from    => $to,
resource        => 'Gaim',
type    => $msg->GetType,
subject => $msg->GetSubject,
body    => $data,
);
}
 
sub connectedCB {
print "Connected\n";
}
 
sub authedCB {
print "Authed\n";
$bot->PresenceSend;
}
 
sub disconnectedCB {
print "Disconnected\n";
}

me <- proud ! ;-) - December 18, 2005 by Stephane Kattoor

I finally finished it (though I expect to have to make some changes in the future …) :
Now I can setup my home automation events in MisterHouse throught my Mozilla Calendar ! The code has been submited and accepted for being integrated in MisterHouse and will be in the next release :-)
Code is here.

Parsing an ICal file with Perl - November 22, 2005 by Stephane Kattoor

I finally almost got it …

Here is a code snippet for parsing and showing pieces of an ICal file :

use strict;
use warnings;

use Data::ICal;
use Data::ICal::DateTime;
use DateTime;

my $cal = Data::ICal->new(filename => 'holidays.ics');

my @events = $cal->events();

foreach my $event (@events) {
        print "summary:", $event->property('summary')->[0]->value, "n";
        print "dtstart:", $event->start, "n";
        print "dtend:", $event->end, "n";
}
print DateTime->now, "n";

What I want to do ? Drive my home automation events with my Mozilla Calendar !! I’ll soon be there, if I gather enough time to do it !

Some pointers :

  • DateTime perl module : a hell of a lot of computations with dates and times
  • Data::ICal perl modules : for all the parsing stuff
  • Data::ICal::DateTime perl module : to get it to work with DateTime
  • new entrys »
    Who am I ?
    Ads