diff --git a/Sam.pl b/Sam.pl index 3e258fd159043efa31067d8504337730b7968aab..f609ebd832be921dd376a7e497c85567c1d2d5af 100755 --- a/Sam.pl +++ b/Sam.pl @@ -12,6 +12,7 @@ use FindBin; use lib "$FindBin::Bin/lib/"; use Logging; use commands::parser; +use sites::parser; my $log = Logging->new('STDOUT', 1); @@ -78,6 +79,7 @@ sub cycle sub setConf { commands::parser::setConf($nick, $irc, $dbh, $log, \%lastID); + sites::parser::setConf($nick, $irc, $dbh, $log, \%lastID); } @@ -161,6 +163,7 @@ sub on_speak my ($nick,$mask) = split(/!/,$user); commands::parser::exec(@args); + sites::parser::exec(@args); } # Boucle des events diff --git a/lib/sites/parser.pm b/lib/sites/parser.pm new file mode 100644 index 0000000000000000000000000000000000000000..442ed295b3e51f29b092edd66d4904b9c0437eba --- /dev/null +++ b/lib/sites/parser.pm @@ -0,0 +1,65 @@ +package sites::parser; + +require Exporter; +our @ISA = qw(Exporter); +our @EXPORT_OK = qw(exec); + +use strict; + +use lib "$FindBin::Bin/lib/"; +use commands::add; +use commands::edit; + +use lib "$FindBin::Bin/lib/sites"; +use residentadvisor; + +my $nick; +my $irc; +my $lastID; + +sub setConf { + my ($nickNew, $ircNew, $dbh, $log, $lastIDnew) = @_; + + $nick = $nickNew; + $irc = $ircNew; + $lastID = $lastIDnew; +} + +sub exec { + my ($kernel, $user, $chan, $msg) = @_; + my ($nick, $mask) = split(/!/,$user); + + my %content; + my $id; + + if ($msg =~ /^Sam(?:,|:) +https?:\/\/(?:www.residentadvisor.net\/event.aspx\?)([0-9]+)/) { + eval { %content = residentadvisor::get($1) }; + } + else { + return 0; + } + + $id = commands::add::exec( + $content{'title'}, + $content{'day'}, + $content{'month'}, + $content{'year'}, + $content{'place'}, + $content{'desc'} + ); + + if ($id) { + $lastID->{$chan->[0]} = $id; + $irc->yield(privmsg => $chan => $content{'title'} . ' le ' . + $content{'day'} . '/' . $content{'month'} . '/' . $content{'year'} + . ' @ ' . $content{'place'} + . ' : ' . $content{'desc'} + ); + } + + commands::edit::exec($id, 'url', $content{'url'}, $chan); + + return 1; +} + +1; diff --git a/lib/sites/residentadvisor.pm b/lib/sites/residentadvisor.pm new file mode 100644 index 0000000000000000000000000000000000000000..be868b78699ca49b7cdfda4b4f1df27856ce8d0a --- /dev/null +++ b/lib/sites/residentadvisor.pm @@ -0,0 +1,33 @@ +package residentadvisor; + +use Inline Python => 'DATA'; + +sub get { + my $id = shift; + my $content = weboob_get($id); + + return %{$content}; +} + +1; + +__DATA__ +__Python__ + +from weboob.core import Weboob +from weboob.capabilities.calendar import CapCalendarEvent + +def weboob_get(id): + w = Weboob() + backends = w.load_backends(CapCalendarEvent) + + event = backends['residentadvisor'].get_event(id) + + return {'title': event.summary, + 'day': event.start_date.strftime('%d'), + 'month': event.start_date.strftime('%m'), + 'year': event.start_date.strftime('%Y'), + 'place': event.location, + 'desc': '%i euros' % event.price, + 'url': event.url} +