Added --ignore-tag option
This commit is contained in:
@@ -32,6 +32,7 @@ This script is intended to be run as a cron job, which might look something like
|
|||||||
-i --feed-id <string> An arbitrary identifier to associate database entries with this feed
|
-i --feed-id <string> An arbitrary identifier to associate database entries with this feed
|
||||||
-l --pod-url <https://...> The pod URL
|
-l --pod-url <https://...> The pod URL
|
||||||
-m --timeout <hours> How long (in hours) to keep attempting failed posts (default 72)
|
-m --timeout <hours> How long (in hours) to keep attempting failed posts (default 72)
|
||||||
|
-n --ignore-tag <#hashtag> Hashtags to filter out. May be specified multiple times (default: none)
|
||||||
-o --fetch-only Don't publish to Diaspora, just queue the new feed items for later
|
-o --fetch-only Don't publish to Diaspora, just queue the new feed items for later
|
||||||
-p --password <********> The D* user password
|
-p --password <********> The D* user password
|
||||||
-r --url-tags Attempt to automatically hashtagify the RSS link URL (default: off)
|
-r --url-tags Attempt to automatically hashtagify the RSS link URL (default: off)
|
||||||
|
|||||||
+18
-3
@@ -30,6 +30,7 @@ my $opts = {
|
|||||||
'timeout' => 72, # hours
|
'timeout' => 72, # hours
|
||||||
};
|
};
|
||||||
my @auto_tags = ();
|
my @auto_tags = ();
|
||||||
|
my @ignored_tags = ();
|
||||||
my @aspect_ids = ();
|
my @aspect_ids = ();
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
@@ -43,6 +44,7 @@ GetOptions(
|
|||||||
'feed-url|f=s',
|
'feed-url|f=s',
|
||||||
'fetch-only|o',
|
'fetch-only|o',
|
||||||
'help|h', => \&usage,
|
'help|h', => \&usage,
|
||||||
|
'ignore-tag|n=s', => \@ignored_tags,
|
||||||
'limit|x=i',
|
'limit|x=i',
|
||||||
'password|p=s',
|
'password|p=s',
|
||||||
'pod-url|l=s',
|
'pod-url|l=s',
|
||||||
@@ -75,6 +77,7 @@ if( $fetched ){
|
|||||||
db_file => $opts->{'database'},
|
db_file => $opts->{'database'},
|
||||||
feed_id => $opts->{'feed-id'},
|
feed_id => $opts->{'feed-id'},
|
||||||
auto_tags => hashtagify( \@auto_tags ),
|
auto_tags => hashtagify( \@auto_tags ),
|
||||||
|
ignored_tags => hashtagify( \@ignored_tags ),
|
||||||
extract_tags_from_url => $opts->{'url-tags'},
|
extract_tags_from_url => $opts->{'url-tags'},
|
||||||
extract_tags_from_title => $opts->{'title-tags'},
|
extract_tags_from_title => $opts->{'title-tags'},
|
||||||
tag_categories => $opts->{'category-tags'},
|
tag_categories => $opts->{'category-tags'},
|
||||||
@@ -163,9 +166,10 @@ sub publish_feed_items {
|
|||||||
sub update_feed {
|
sub update_feed {
|
||||||
my ( $feed, %params ) = @_;
|
my ( $feed, %params ) = @_;
|
||||||
|
|
||||||
$params{'auto_tags'} = 0 unless defined $params{'auto_tags'};
|
$params{'auto_tags'} = [] unless defined $params{'auto_tags'};
|
||||||
$params{'extract_tags_from_url'} = 0 unless defined $params{'extract_tags_from_url'};
|
$params{'extract_tags_from_url'} = 0 unless defined $params{'extract_tags_from_url'};
|
||||||
$params{'tag_categories'} = 0 unless defined $params{'tag_categories'};
|
$params{'tag_categories'} = 0 unless defined $params{'tag_categories'};
|
||||||
|
$params{'ignored_tags'} = [] unless defined $params{'ignored_tags'};
|
||||||
|
|
||||||
my $items = get_feed_items( $feed, %params );
|
my $items = get_feed_items( $feed, %params );
|
||||||
my $dbh = connect_to_db( $params{'db_file'} );
|
my $dbh = connect_to_db( $params{'db_file'} );
|
||||||
@@ -211,9 +215,10 @@ sub get_feed_items {
|
|||||||
my @items = ();
|
my @items = ();
|
||||||
my $list = decode_feed( $feed );
|
my $list = decode_feed( $feed );
|
||||||
|
|
||||||
$params{'auto_tags'} = 0 unless defined $params{'auto_tags'};
|
$params{'auto_tags'} = [] unless defined $params{'auto_tags'};
|
||||||
$params{'extract_tags_from_url'} = 0 unless defined $params{'extract_tags_from_url'};
|
$params{'extract_tags_from_url'} = 0 unless defined $params{'extract_tags_from_url'};
|
||||||
$params{'tag_categories'} = 0 unless defined $params{'tag_categories'};
|
$params{'tag_categories'} = 0 unless defined $params{'tag_categories'};
|
||||||
|
$params{'ignored_tags'} = [] unless defined $params{'ignored_tags'};
|
||||||
|
|
||||||
foreach my $item ( @$list ){
|
foreach my $item ( @$list ){
|
||||||
my $link = $item->{'link'};
|
my $link = $item->{'link'};
|
||||||
@@ -310,13 +315,22 @@ sub get_feed_items {
|
|||||||
}
|
}
|
||||||
else { $guid = $link }
|
else { $guid = $link }
|
||||||
|
|
||||||
|
@hashtags = @{ hashtagify( \@hashtags ) };
|
||||||
|
|
||||||
|
# filter out ignored tags
|
||||||
|
for( my $t = 0; $t < @hashtags; $t++ ){
|
||||||
|
foreach my $ignored ( @{$params{'ignored_tags'}} ){
|
||||||
|
splice( @hashtags, $t, 1 ) if $hashtags[$t] eq $ignored;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
my $obj = {
|
my $obj = {
|
||||||
guid => $guid,
|
guid => $guid,
|
||||||
title => $item->{'title'},
|
title => $item->{'title'},
|
||||||
link => $link,
|
link => $link,
|
||||||
image => $image,
|
image => $image,
|
||||||
image_title => $image_title,
|
image_title => $image_title,
|
||||||
hashtags => hashtagify( \@hashtags ),
|
hashtags => \@hashtags,
|
||||||
};
|
};
|
||||||
|
|
||||||
$items[@items] = $obj;
|
$items[@items] = $obj;
|
||||||
@@ -564,6 +578,7 @@ sub usage {
|
|||||||
print " -i --feed-id <string> An arbitrary identifier to associate database entries with this feed\n";
|
print " -i --feed-id <string> An arbitrary identifier to associate database entries with this feed\n";
|
||||||
print " -l --pod-url <https://...> The pod URL\n";
|
print " -l --pod-url <https://...> The pod URL\n";
|
||||||
print " -m --timeout <hours> How long (in hours) to keep attempting failed posts (default 72)\n";
|
print " -m --timeout <hours> How long (in hours) to keep attempting failed posts (default 72)\n";
|
||||||
|
print " -n --ignore-tag <#hashtag> Hashtags to filter out. May be specified multiple times (default: none)\n";
|
||||||
print " -o --fetch-only Don't publish to Diaspora, just queue the new feed items for later\n";
|
print " -o --fetch-only Don't publish to Diaspora, just queue the new feed items for later\n";
|
||||||
print " -p --password <********> The D* user password\n";
|
print " -p --password <********> The D* user password\n";
|
||||||
print " -r --url-tags Attempt to automatically hashtagify the RSS link URL (default: off)\n";
|
print " -r --url-tags Attempt to automatically hashtagify the RSS link URL (default: off)\n";
|
||||||
|
|||||||
Reference in New Issue
Block a user