Skip to content

Instantly share code, notes, and snippets.

@tf0054
Created March 17, 2012 16:40
Show Gist options
  • Save tf0054/2062009 to your computer and use it in GitHub Desktop.
Save tf0054/2062009 to your computer and use it in GitHub Desktop.
ekitanのバス時刻表をパースに次のバスを表示
#!/usr/bin/perl -w
use HTML::TableExtract;
use Data::Dumper;
MAIN:{
my %hashTT;
my $strLine = "";
my $strTmp = "";
open(I,$ARGV[0])||die($ARGV[0]);
my @lines = <I>;
chomp @lines;
$source = join('',@lines);
close(I);
my $te = new HTML::TableExtract(count => 2);
$te->parse($source);
foreach $table ($te->table_states) {
print "Table (", join(',', $table->coords), "):\n";
foreach my $row ($table->rows) {
$strLine = join(',', @$row)."\n";
# strip non-digits characters.
$strTmp = @{$row}[1];
$strTmp =~ s/[^\d]+/^/g;
$strTmp =~ s/^\^(.*)\^$/$1/g;
my @aryTmp = split(/\^/,$strTmp);
if(@{$row}[0] =~ /\d+/){
$hashTT{@{$row}[0]} = \@aryTmp;
}
}
print Dumper \%hashTT;
}
my ($sec,$min,$hour,$mday,$mon,$year,$wno) = localtime(time);
print "-"x48;
print "\n";
print "Now is $hour:$min.\n";
if(exists($hashTT{$hour})){
foreach my $i (@{$hashTT{$hour}}){
if($min<$i){
print "The next bus will come on $hour:$i.";
last;
}
}
if(exists($hashTT{$hour+1})){
$i = @{$hashTT{$hour+1}}[0];
print "The next bus will come on ".($hour+1).":$i.";
last;
}
}
print "We have no bus now.\n";
print "-"x48;
}
# http://bus.ekitan.com/rosen/Rp800?t=0&b=290632&b3=0&r2=42&s=522&n=0&f=0&com=29&cn=%8B%9E%95l%8B}%8Ds%83o%83X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment