Skip to content

Instantly share code, notes, and snippets.

@scottwalters
Created April 5, 2015 08:40
Show Gist options
  • Save scottwalters/9e7eb0242d2c1734283b to your computer and use it in GitHub Desktop.
Save scottwalters/9e7eb0242d2c1734283b to your computer and use it in GitHub Desktop.
TBAG filtering Facebook's RSS feed on tags so that Mailchimp only sends out emails on tagged posts
#!/home/biketempe/bin/perl
#!/usr/local/bin/perl
use 5.019;
use strict;
use warnings;
use experimental 'postderef', 'signatures';
use CGI;
use CGI::Carp 'fatalsToBrowser';
use XML::RSS;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->agent('Custom RSS Feed Splitter for Mailchimp [email protected]/0.1');
try_again:
my $tries = 3;
my $req = HTTP::Request->new(GET => 'https://www.facebook.com/feeds/page.php?format=rss20&id=58276904001');
my $res = $ua->request($req);
goto try_again if $res->is_error and $tries--;
die "failure" if $res->is_error;
my $rss = XML::RSS->new( version => '2.0' );
$rss->parse($res->decoded_content);
my $tag = CGI::param('tag') or die;
$tag = "#$tag" if $tag !~ m/^#/;
for my $i ( reverse 0 .. $#{ $rss->{items} } ) {
if( $rss->{items}->[$i]->{description} !~ m/$tag/ ) {
splice @{ $rss->{items} }, $i, 1, ();
}
}
print "Content-type: application/rss+xml\r\n\r\n";
print $rss->as_string;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment