Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Atom Feed for Chatterbox 60

by tobyink (Abbot)
on Oct 14, 2012 at 10:04 UTC ( #998947=CUFP: print w/replies, xml ) Need Help??

#!/usr/bin/env perl use HTML::HTML5::Parser; use Object::Tap -package => 'XML::Atom::Base'; use XML::Atom::Feed; use XML::Atom::Entry; use XML::Atom::Person; use XML::LibXML 2.00; my $list = HTML::HTML5::Parser -> new -> parse_file('', { ignore_http_respo +nse_code => 1 }) -> getElementsByTagName('dl') -> get_node(1); my $feed = XML::Atom::Feed->new; $feed->title('PerlMonks Chatterbox'); $feed->id(',2012:perlmonks:chatterbox'); my $dt; foreach my $node ($list->getChildrenByTagName('*')) { ($dt = $node) && next if $node->tagName eq 'dt'; $feed->add_entry( XML::Atom::Entry->new->tap( title => [ $node->textContent ], id => [ join ':', $feed->id, $dt->{id} ], author => [ XML::Atom::Person->new->tap( name => [ $dt->getElementsByTagName('a')->get_node +(1)->textContent ], uri => [ ''. $dt->getElementsByTagName('a')->get_node(1)->{ +href} ], ) ], published => [ $dt->getElementsByTagName('small')->get_node(1)->textC +ontent, ], ) ); } print $feed->as_xml;

Fixing up the datetimes to meet the Atom 1.0 spec is left as an exercise for the reader.

perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re: Atom Feed for Chatterbox 60
by mje (Curate) on Oct 15, 2012 at 13:16 UTC

    Thanks tobyink. I had to make a slight change for behind a proxy server:

    my $ua = LWP::UserAgent->new; $ua->env_proxy; my $list = HTML::HTML5::Parser -> new -> parse_file('', { ignore_http_respo +nse_code => 1, user_agent => $ua }) -> getElementsByTagName('dl') -> get_node(1);

    Also, HTML::HTML5::Parser failed its tests for me. When I looked at the test results I saw other people/smokers had hit this too so I reported it at 07ua.t fails.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://998947]
Approved by moritz
[LanX]: choroba: subversive (as usual ;)
[james28909]: i dunno, if i didnt have so little experience in linux i would swap. but it would be to much of a learning curve for me right now.
[choroba]: Low-end is defined as the Perl that generates millions of income
[choroba]: sorry, that's high-end, of coursse
[choroba]: low end, in my talk, will be code that "we don't touch because it works" and noone knows why
[choroba]: I want to present the most bizzare bugs and misfeatures I met when working for a large financial institution
[choroba]: I already gave a similar talk to my friends in a pub and at an internal conference at work and people liked it, so maybe...
[choroba]: LanX: That's the heritage, I can't do anything else
[RonW]: Sounds like some system my employer has "It does exactly what we need it to do and can't afford to risk anything we can't prove is 100% compatible"
[marto]: choroba sounds interesting

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (11)
As of 2017-05-22 21:35 GMT
Find Nodes?
    Voting Booth?