Created
April 16, 2009 13:06
-
-
Save shelling/96403 to your computer and use it in GitHub Desktop.
catch enrollment tidings from NTU ACA and render rss
This file contains 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
#!/usr/bin/env perl | |
# shelling <shelling@cpan.org> | |
# This script can get enrollment tidings(招生資訊) | |
# from 台灣大學教務處(NTU ACA) and render rss list | |
use utf8; | |
no warnings; | |
use CGI::RSS; | |
use pQuery; | |
use LWP::Simple; | |
use autobox::Core; | |
use Data::Dumper; | |
use Encode qw(encode decode); | |
my @result; | |
my $url = "http://www.aca.ntu.edu.tw/aca2007/access/acc_index.asp"; | |
$p = decode "big5", get($url); | |
pQuery($p) | |
->find("div#content") | |
->find("table") | |
->find("tbody") | |
->find("tr") | |
->each(sub{ | |
my $self = $_; | |
my $h = {}; | |
my $first = pQuery( $self->firstChild() )->find("a")->html(); | |
if ($first) { | |
$h->{title} = $first; | |
$h->{url} = pQuery( $self->firstChild() )->find("a")->[0]->getAttribute("href"); | |
} else { | |
$h->{title} = pQuery($self->firstChild)->html(); | |
} | |
my $d = pQuery($self->lastChild)->html(); | |
$d =~ s{/}{-}g; | |
$h->{date} = $d; | |
push @result, $h; | |
}); | |
my $rss = CGI::RSS->new; | |
print $rss->header; | |
print $rss->begin_rss( | |
title => "NTU ACA Tidings", | |
link => "http://www.aca.ntu.edu.tw/aca2007/access/acc_index.asp" | |
); | |
for (@result) { | |
print $rss->item( | |
$rss->title ($_->{title}), | |
$rss->description ($_->{title}), | |
$rss->link ($_->{url}), | |
$rss->date ($_->{date}), | |
$rss->pubDate ($_->{date}), | |
); | |
} | |
print $rss->finish_rss; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment