apply filters in cronjob, too

master
Benjamin 'blindCoder' Schieder 2017-04-24 08:17:30 +02:00
parent 70c6a792db
commit 0fd87caee4
1 changed files with 37 additions and 16 deletions

View File

@ -5,6 +5,7 @@ use Data::Dumper;
use URI::Escape; use URI::Escape;
use JSON; use JSON;
use RSSTootalizer::Feed; use RSSTootalizer::Feed;
use RSSTootalizer::Filter;
use RSSTootalizer::User; use RSSTootalizer::User;
use RSSTootalizer::Entry; use RSSTootalizer::Entry;
@ -51,24 +52,44 @@ FEED: foreach my $feed (@feeds){
$entry{id} = $entry->id(); $entry{id} = $entry->id();
$entry{tags} = join(", ", $entry->tags()); $entry{tags} = join(", ", $entry->tags());
my $user = $feed->user(); my $do_post = 0;
my $status = $feed->{data}->{format}; my @filters = $feed->filters();
$status =~ s/{ID}/$entry{id}/g; foreach my $filter (@filters){
$status =~ s/{Title}/$entry{title}/g; if ($filter->apply($entry)){
$status =~ s/{Link}/$entry{link}/g; if ($filter->{data}->{type} eq "white"){
$status =~ s/{Content}/$entry{content}/g; $do_post = 1;
$status =~ s/{Author}/$entry{author}/g; } else {
$status =~ s/{Issued}/$entry{issued}/g; $do_post = 0;
$status =~ s/{Modified}/$entry{modified}/g; }
$status =~ s/{Tags}/$entry{tags}/g; } else {
if ($filter->{data}->{type} eq "white"){
$do_post = 0;
} else {
$do_post = 1;
}
}
}
$status =~ s/'/"/g; # TODO if ($do_post){
my $user = $feed->user();
my $status = $feed->{data}->{format};
$status =~ s/{ID}/$entry{id}/g;
$status =~ s/{Title}/$entry{title}/g;
$status =~ s/{Link}/$entry{link}/g;
$status =~ s/{Content}/$entry{content}/g;
$status =~ s/{Author}/$entry{author}/g;
$status =~ s/{Issued}/$entry{issued}/g;
$status =~ s/{Modified}/$entry{modified}/g;
$status =~ s/{Tags}/$entry{tags}/g;
open(DATA, "./post_status.bash '$user->{data}->{access_token}' '$user->{data}->{instance}' '$status'|"); $status =~ s/'/"/g; # TODO
my $reply = "";
{ open(DATA, "./post_status.bash '$user->{data}->{access_token}' '$user->{data}->{instance}' '$status'|");
local $/ = undef; my $reply = "";
$reply = <DATA>; {
local $/ = undef;
$reply = <DATA>;
}
} }
my %ne; my %ne;