#!/usr/bin/perl -w # # idos2mob # # Josef Kufner # # tmp file $tmp_fn = "/var/tmp/idos2mob-$$"; # check cmd line argument if (defined($ARGV[0])) { $url = $ARGV[0]; } else { print "Usage: $0 url\n"; exit 1; } # download data $html = `links -source "$url"`; # replacing in shit-html $html =~ s/(bus
(\d)/> \;
$1/g; $html =~ s/(\d)
 \;$tmp_fn"; print TMP "$html"; $text = `links -dump "$tmp_fn" -width 512`; close TMP; unlink $tmp_fn; # replacing in text $text =~ s/spoj je obsluhovan nizkopodlaznim vozidlem/nizkopodl./g; $text =~ s/Servisni banner neni definovan!//g; $text =~ s/prestup na Metro/(=M=)/g; $text =~ s/\(=M=\) - \(=M=\)//g; $text =~ s/ */\t/g; $text =~ s/[ \t]*\n/\n/g; # explode to lines @line = split("\n", $text); # find table begin for ($l = 0; $line[$l] !~ /----*/g; $l++) { ; } $l += 3; $date = "(oops)"; $hr = "-----------------------"; $line[1] =~ s/\t//; $out = $line[1]."\n$hr\n\n"; $title = $line[1]; $title =~ s/^ *(.*) *$/$1/; $begin_date = ""; $begin_time = ""; for (; !($line[$l] eq ""); $l++) { # explode table line @cel = split("\t", $line[$l]); if ($cel[1] =~ /[a-zA-Z]/) { @cel = ("", @cel); $cel[1] = ";,;,;"; } # format cels to output if (!($cel[1] eq ";,;,;")) { $date = $cel[1]; $begin_date = $begin_date eq "" ? $date : $begin_date; $begin_time = $begin_time eq "" ? $cel[4] : $begin_time; } $out .= $cel[2]."\n" .($cel[3] eq ";,;,;" ? "" : " pr: $date $cel[3]\n") .($cel[4] eq ";,;,;" ? "" : " od: $date $cel[4]\n $cel[6]\n") .($cel[5] eq ";,;,;" ? "" : " pozn: $cel[5]\n") ."\n"; } # summary $line[$l + 1] =~ s/\t//; $line[$l + 1] =~ s/km, /km\n/; $out .= "$hr\n".$line[$l + 1]."\n"; # footer for (;$line[$l] !~ /Vytisteno z/; $l++) {} $line[$l] =~ s/\t//; $line[$l + 1] =~ s/\t//; $out .= "\n\n$hr\n".$line[$l]."\n".$line[$l + 1]."\n"; open TMP, ">$tmp_fn"; print TMP "$out"; close TMP; $begin_date =~ s/\.(\d\.)/.0$1/; $begin_date =~ s/(\d?\d)\.(\d?\d)\./$2-$1/; $begin_date =~ s/-(\d)$/-0$1/; $begin_time = ($begin_time =~ /\d\d:\d\d/) ? $begin_time : "0$begin_time"; $title =~ s/[\/\\*]//g; system "/usr/local/bin/ussp-push \"/dev/rfcomm0\" \"$tmp_fn\" \"$begin_date-$begin_time $title.txt\""; unlink $tmp_fn;