Advertisement
Guest User

lectures.pl

a guest
Sep 21st, 2014
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.52 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. #
  3. foreach $arg (@ARGV){
  4.   if (($arg eq "-t")||($arg eq "-d")){
  5.     $option = $ARGV[0];
  6.     next;
  7.   }
  8.  
  9.   $search = uc($arg);
  10.   $url = "http://www.timetable.unsw.edu.au/current/$search.html";
  11.  
  12.   open F, "wget -q -O- $url |" or die "cannot open the webpage\n";
  13.   @lines = <F>;
  14.   $sem = "null\n";
  15.   $len = @lines;
  16.   $i = 0;
  17.   while ($i < $len){
  18.     $pre = $sem;
  19.     $day = "null";
  20.     $time = "null";
  21.     if (($lines[$i] =~ /Lecture/ig) and !($lines[$i] =~ /Sequence/ig)){
  22.       $j = $i + 3;
  23.       if ($lines[$j] =~ /([XS][12])/gi){
  24.         $sem = $1;
  25.         $j += 3;
  26.         chomp($lines[$i]);
  27.         $lines[$j] =~ s/<.*?>//ig;
  28.         $lines[$j] =~ s/^\s+/ /ig;
  29.         if (defined($option)){
  30.           while($lines[$j] =~ /([A-Z][a-z]{2})[^A-Za-z]?([0-9]{2}:[0-9]{2})( - )([0-9]{2}:[0-9]{2})/cig){
  31.             $day = $1;
  32.             $time = $2;    
  33.         $time =~ s/:/./;
  34.         $time_e = $3;
  35.         $time_e =~ s/:/./;
  36.             if ($time ne $pre){
  37.               if ($option eq "-d"){
  38.         $time = int($time);
  39.         $time_e = int($time_e + 0.99);
  40.         print "start : $time\n";
  41.         print "end: $time_e\n";
  42.         #while ($k < $time_e){
  43.                 #  printf "%s %s %s %s\n",$sem, $search, $day, $k;
  44.         #}
  45.               }
  46.             }
  47.           }
  48.         }
  49.         else {
  50.           $sem .= $lines[$j];
  51.           chomp ($sem);
  52.           if (($pre ne $sem) && !($sem =~ /[XS][12][ ]$/gi)){
  53.             printf "%s: %s\n", $search, $sem;
  54.           }
  55.         }
  56.       }
  57.     }
  58.     $i += 1;
  59.   }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement