Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

RSS Feeds on iPod

by munchie (Monk)
on Feb 16, 2004 at 17:27 UTC ( [id://329382]=CUFP: print w/replies, xml ) Need Help??

I guess this could qualify as a CUFP. It read a config file that looks something like this:

H iPodLounge http://www.ipodlounge.com/index.xml title description BoingBoing http://boingboing.net/rss.xml title description TopSellingGames http://www.lockergnome.com/amazon/rss.php?id=95 title

Where the 1st line is the drive letter of the iPod, and the other lines are the title of the output file, then the url, then the attributes you want to be included within the txt file. Note, I parsed the xml and stripped html by hand (no modules) because this is a science project (Pennsylvania Junior Academy of Science) and I'll probably get a better score if I don't just use modules to do everything for me. Also note, this is a Windows only program- no iPod on linux.

#! Perl use strict; use diagnostics; use LWP::UserAgent; my @feedlist; open NEWSCONFIG, "inews.cfg"; while(<NEWSCONFIG>) { push(@feedlist,$_); } close NEWSCONFIG; foreach(@feedlist) { chomp; } my $driveletter = shift(@feedlist); foreach my $newsfeed (@feedlist) { my @includes; my $url; my $filename; @includes = split(/\s/, $newsfeed); $filename = shift(@includes); $url = shift(@includes); ######-Get Feeds From The Internet-##### my $ua = LWP::UserAgent->new; $ua->agent("iNews News Aggregator"); # Create a request my $req = HTTP::Request->new(GET => $url); # Pass request to the user agent and get a response back my $feedObj = $ua->request($req); # Check the outcome of the response ######-----------------------------##### my @items; my $feedtext = $feedObj->content; print "Generating Output.."; $feedtext =~ s/\n//g; print ".."; open IPOD, "> $driveletter".":\\notes\\"."$filename" or die; @items = split/<item/, $feedtext; shift(@items); print ".."; foreach my $item (@items) { foreach my $attrib (@includes) { if ($item =~ /<$attrib>(.*)<\/$attrib>/) { my $toPod = $1; ###-Strip Markup Tags-### $toPod =~ s/<.+?>//g; $toPod =~ s/&quot\;//g; $toPod =~ s/&nbsp\;//g; $toPod =~ s/&lt;.+?&gt\;//g; ###-------------------### print IPOD "$toPod\n"; } } print IPOD "*\n"; } close IPOD; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://329382]
Approved by Corion
Front-paged by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-20 03:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found