twitter 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/perl
  2. # Copyright (C) 2009, 2012 Alex Schroeder <alex@gnu.org>
  3. #
  4. # This program is free software: you can redistribute it and/or modify it under
  5. # the terms of the GNU General Public License as published by the Free Software
  6. # Foundation, either version 3 of the License, or (at your option) any later
  7. # version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License along with
  14. # this program. If not, see <http://www.gnu.org/licenses/>.
  15. use CGI qw/:standard/;
  16. use CGI::Carp qw(fatalsToBrowser);
  17. use LWP::UserAgent;
  18. use XML::RSS;
  19. if (not param('feed')) {
  20. print header(),
  21. start_html('Description Stripping'),
  22. h1('Description Stripping'),
  23. p('Removes the description of an article if it matches the title. This is most useful for Twitter and other microblogging services.'),
  24. p('Example input:', code('http://api.twitter.com/1/statuses/user_timeline.rss?screen_name=kensanata')),
  25. start_form(-method=>'GET'),
  26. p('Feed: ', textfield('feed', '', 40), checkbox('Strip username'),
  27. submit()),
  28. end_form(),
  29. end_html();
  30. exit;
  31. }
  32. $ua = LWP::UserAgent->new;
  33. $request = HTTP::Request->new('GET', param('feed'));
  34. $response = $ua->request($request);
  35. $data = $response->content;
  36. exit unless $data;
  37. print header(-type=>$response->content_type);
  38. $rss = new XML::RSS;
  39. $rss->parse($data);
  40. foreach my $i (@{$rss->{items}}) {
  41. $i->{description} = undef if $i->{description} eq $i->{title};
  42. $i->{title} =~ s/^.*?: // if param('Strip username');
  43. }
  44. print $rss->as_string;