Created
April 5, 2015 08:40
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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