use Date::Calendar::Year;
use HTML::TableExtract;
use LWP::UserAgent;
-use IO::File;
-use XML::Writer;
+use XML::Simple;
use vars qw($ua %opts %faculty);
my ($response);
foreach(split(" ",$class{'days'})) {
push @days, Decode_Day_of_Week($_);
}
- my @off = (off_for_holidays(%class),off_for_exams(%class));
+ my @off = @{$row->{'off'}};
for($today = ($today > $firstday ? $today : $firstday); $today < $lastday; $today++) {
next unless(grep($_ == Day_of_Week($today->date), @days));
next if(grep($_ == $today, @off));
sub off_for_holidays {
my %class = @_;
+ my %days = (M => "Mon", T => "Tue", W => "Wed", R => "Thu", F => "Fri", S => "Sat", U => "SU");
+ my $d = $class{'days'};
+ $d =~ s/([MTWRFS])/ $days{$1}/g;
+ $d =~ s/^ //;
$class{'duration'} =~ /(\d\d\d\d)(\d\d)(\d\d)-(\d\d\d\d)(\d\d)(\d\d)/;
my $days = Delta_Days($1,$2,$3,$4,$5,$6);
my $firstday = Date::Calc->new($1,$2,$3);
my $year = Date::Calendar::Year->new($1, $opts{'holidays'});
my @holidays=();
my @days=();
- foreach(split(" ",$class{days})) {
+ foreach(split(" ",$d)) {
$days[Decode_Day_of_Week($_)] = 1;
}
foreach ($year->search("")) {
$row->[4] =~ s/ - /-/;
$row->[3] =~ s/(ON|MAIN) CAMPUS\n|Palo Alto Building \d* //ig;
$row->[3] =~ s/\n/ /g;
- push @schedule, {
+ my %class = (
id => $classid,
title => capitalize($title),
instructor => $row->[6],
end => $end || undef,
duration => $row->[4],
location => $row->[3],
- };
+ );
+ my @off = ( map { "$_"; } (off_for_holidays(%class), off_for_exams(%class)));
+ $class{'off'} = [ @off ] if (@off);
+ push @schedule, \%class;
}
}
return @schedule;
@mhc = @mhc2;
}
foreach my $row (@schedule) {
+ #my @day = map { "!" . $_ } (off_for_holidays(%$row),off_for_exams(%$row));
+ my @day = @{$row->{'off'}};
map {s/\n/-/g if defined; $_} %$row;
my $id=generate_id($row->{'id'});
$row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
$row->{'days'} =~ s/^ //;
#$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
- my @day = map { "!" . $_ } (off_for_holidays(%$row),off_for_exams(%$row));
$current = "";
#print "# $id\n";
$current .= "X-SC-Subject: " . $row->{'title'} . "\n";
$row->{'days'} =~ s/([MTWRFS])/ $days{$1}/g;
$row->{'days'} =~ s/^ //;
#$row->{'duration'} =~ s/(\d\d)-(\d\d)-(\d\d)/20$3$1$2/g;
- my @day = (off_for_holidays(%$row),off_for_exams(%$row));
+ my @day = @{$row->{'off'}};
my $day = "";
if(exists($day[0])) {
$day = join(";", @day);
sub do_xml_schedule {
my $file = shift if (defined $_[0] and $_[0] !~ /^\d/);
- my ($output, $writer);
+ my $schedule = { class => [ get_schedule(@_) ] };
+ my $xml = XMLout($schedule, NoAttr => 1, RootName => 'schedule');
if($file) {
- $output = new IO::File(">$file");
- $writer = new XML::Writer(OUTPUT => $output, DATA_MODE => 1);
+ open FH, ">$file";
+ print FH $xml;
+ close FH;
} else {
- $writer = new XML::Writer(DATA_MODE => 1);
- }
- my @schedule = get_schedule(@_);
- $writer->startTag("schedule");
- foreach my $class (@schedule) {
- $writer->startTag("class");
- foreach my $key (sort keys %$class) {
- $writer->dataElement($key, $class->{$key});
- }
- $writer->endTag("class");
+ print $xml;
}
- $writer->endTag("schedule");
- $writer->end();
- close $output if $file;
}
sub do_html_schedule {