40 lines
1012 B
Perl
40 lines
1012 B
Perl
package StatusCafe;
|
|
|
|
use utf8;
|
|
use strict;
|
|
use warnings;
|
|
|
|
use HTTP::Tiny;
|
|
use Mojo::DOM;
|
|
use Mojo::Util;
|
|
|
|
use Exporter qw(import);
|
|
our @EXPORT = qw(statuscafe);
|
|
|
|
sub statuscafe {
|
|
# fetch DOM from status.cafe
|
|
my $_response =
|
|
HTTP::Tiny->new(keep_alive => 0)->get('https://status.cafe/users/' . $_[0]);
|
|
return "$_response->{status} $_response->{reason}"
|
|
unless $_response->{success};
|
|
bless $_response, __PACKAGE__;
|
|
my $_dom =
|
|
Mojo::DOM->new->parse(Mojo::Util::decode('UTF-8', $_response->{content}));
|
|
|
|
# get the relevant text from the latest status
|
|
my $_info =
|
|
$_dom->find('div.status-username')->first->all_text;
|
|
my $_content =
|
|
$_dom->find('p.status-content')->first->all_text;
|
|
|
|
# now turn $_info into a form we can use more easily
|
|
my ($_emoji) =
|
|
$_info =~
|
|
/[\p{Emoji}\p{EMod}\p{EComp}\p{EBase}\p{EPres}\p{Emoticons}\p{ExtPict}]/g;
|
|
my ($_ago) =
|
|
$_info =~ /((\d{1,4})\s([a-z\s]{1,}))$/g;
|
|
|
|
return ($_emoji, $_ago, $_content);
|
|
}
|
|
|
|
1; |