Skip to content

Instantly share code, notes, and snippets.

@briandfoy
Created December 6, 2013 12:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briandfoy/7822706 to your computer and use it in GitHub Desktop.
Save briandfoy/7822706 to your computer and use it in GitHub Desktop.
Read the twitters in the RSS. I made this stupid little program at "patch -p1" http://patch.pm/p1/ I'm not making it easy for you to use. I don't need Twitter on my case. If you want it bad enough, you'll figure out how to set it up. :)
#!/usr/local/bin/perl5.16.2
use v5.10;
use strict;
use open qw(:std :utf8);
use Net::Twitter;
use XML::RSS;
my $twitter = create_twitter();
# somehost.example.com/cgi-bin/twitter.cgi?merlyn;briandfoy_perl
my @users = split /;/, $ENV{QUERY_STRING};
@users = qw( TheRock ) unless @users;
my $rss = create_rss( @users );
foreach my $user ( @users ) {
my $tweets = $twitter->user_timeline( { screen_name => $user } );
foreach my $tweet ( @$tweets ) {
$rss->add_item(
title => "$user: $tweet->{text}",
link => "https://twitter.com/$user/status/$tweet->{id}",
description => $tweet->{text},
);
}
}
print
"Content-type: application/rss+xml\n\n" .
$rss->as_string;
sub create_twitter {
my $nt = Net::Twitter->new(
traits => [qw/OAuth API::RESTv1_1/],
map { $_ => $ENV{"twitter_$_"} || die "ENV twitter_$_ not set" }
qw(
consumer_secret
consumer_key
access_token
access_token_secret
)
);
die "Could not make Twitter object!\n" unless defined $nt;
return $nt;
}
sub create_rss {
my( $user ) = @_;
my $rss = XML::RSS->new(version => '1.0');
$rss->channel(
title => "Twitter RSS ",
link => "https://twitter.com/$user",
description => "Read Tweets in RSS",
);
return $rss;
}
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment