Skip to content
Extraits de code Groupes Projets
Valider de39779e rédigé par Alexandre Morignot's avatar Alexandre Morignot
Parcourir les fichiers

Sam understantds residentadvisor links

parent b6509291
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -12,6 +12,7 @@ use FindBin; ...@@ -12,6 +12,7 @@ use FindBin;
use lib "$FindBin::Bin/lib/"; use lib "$FindBin::Bin/lib/";
use Logging; use Logging;
use commands::parser; use commands::parser;
use sites::parser;
my $log = Logging->new('STDOUT', 1); my $log = Logging->new('STDOUT', 1);
...@@ -78,6 +79,7 @@ sub cycle ...@@ -78,6 +79,7 @@ sub cycle
sub setConf sub setConf
{ {
commands::parser::setConf($nick, $irc, $dbh, $log, \%lastID); commands::parser::setConf($nick, $irc, $dbh, $log, \%lastID);
sites::parser::setConf($nick, $irc, $dbh, $log, \%lastID);
} }
...@@ -161,6 +163,7 @@ sub on_speak ...@@ -161,6 +163,7 @@ sub on_speak
my ($nick,$mask) = split(/!/,$user); my ($nick,$mask) = split(/!/,$user);
commands::parser::exec(@args); commands::parser::exec(@args);
sites::parser::exec(@args);
} }
# Boucle des events # Boucle des events
......
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;
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}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter