Fix !drink command
This commit is contained in:
@@ -20,14 +20,13 @@ use version; our $VERSION = qw (1.0);
|
|||||||
use Exporter qw (import);
|
use Exporter qw (import);
|
||||||
our @EXPORT_OK = qw (Drink);
|
our @EXPORT_OK = qw (Drink);
|
||||||
|
|
||||||
my @MONTH = qw (yanvar fevral mart aprel may iyun iyul avgust sentyabr oktyabr noyabr dekabr);
|
|
||||||
my $c = LoadConf ();
|
my $c = LoadConf ();
|
||||||
|
|
||||||
sub Drink {
|
sub Drink {
|
||||||
my $drinkCallBack = sub {
|
my $drinkCallBack = sub {
|
||||||
my $ret;
|
my $ret;
|
||||||
my ($dayNum, $monthNum) = (localtime ())[3, 4];
|
my ($dayNum, $monthNum) = (localtime ())[3, 4];
|
||||||
my $url = sprintf 'https://kakoysegodnyaprazdnik.ru/baza/%s/%s', $MONTH[$monthNum], $dayNum;
|
my $url = 'https://prazdniki-segodnya.ru/';
|
||||||
my $r;
|
my $r;
|
||||||
|
|
||||||
for (1..3) {
|
for (1..3) {
|
||||||
@@ -42,28 +41,32 @@ sub Drink {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($r->{success}) {
|
if ($r->{success}) {
|
||||||
# TODO: Handle unexpected content
|
my $p = HTML::TokeParser->new(\$r->{content});
|
||||||
my $p = HTML::TokeParser->new (\$r->{content});
|
|
||||||
my @a;
|
my @a;
|
||||||
my @holiday;
|
my %holiday;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
$#a = -1;
|
$#a = -1;
|
||||||
@a = $p->get_tag ('span'); ## no critic (Variables::RequireLocalizedPunctuationVars)
|
@a = $p->get_tag ('div'); ## no critic (Variables::RequireLocalizedPunctuationVars)
|
||||||
|
|
||||||
if ($#{$a[0]} > 2 && defined $a[0][1]->{itemprop} && $a[0][1]->{itemprop} eq 'text') {
|
if ($#{$a[0]} > 2) {
|
||||||
push @holiday,'* ' . decode ('UTF-8', $p->get_trimmed_text ('/span'));
|
my @shitty_array = $a[0];
|
||||||
|
foreach my $item (@shitty_array) {
|
||||||
|
if (ref $item) {
|
||||||
|
foreach my $item1 (@{$item}) {
|
||||||
|
my %h = eval { %{$item1} };
|
||||||
|
|
||||||
|
if (defined ($h{class}) && $h{class} eq 'list-group-item text-monospace') {
|
||||||
|
$holiday {'* ' . decode ('UTF-8', $p->get_trimmed_text ('/div'))} = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} while ($#{$a[0]} > 1);
|
} while ($#{$a[0]} > 1);
|
||||||
|
|
||||||
if ($#holiday > 0) {
|
if (int (keys %holiday) > 0) {
|
||||||
# cut off something weird, definely not a "holyday"
|
$ret = join "\n", sort (keys %holiday);
|
||||||
$#holiday = $#holiday - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($#holiday > 0) {
|
|
||||||
$ret = join "\n", @holiday;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$log->warn (sprintf '[WARN] Server return status %s with message: %s', $r->{status}, $r->{reason});
|
$log->warn (sprintf '[WARN] Server return status %s with message: %s', $r->{status}, $r->{reason});
|
||||||
|
|||||||
Reference in New Issue
Block a user