[Assorted-commits] SF.net SVN: assorted: [195] movie-lookup/trunk/src
Brought to you by:
yangzhang
From: <yan...@us...> - 2007-12-25 04:47:04
|
Revision: 195 http://assorted.svn.sourceforge.net/assorted/?rev=195&view=rev Author: yangzhang Date: 2007-12-24 20:47:07 -0800 (Mon, 24 Dec 2007) Log Message: ----------- - fixed script inputs to use sample-hbo.txt - rewrote movielookup.scala; added rated-schedule mode as default - redid makefile Modified Paths: -------------- movie-lookup/trunk/src/MovieLookup.scala movie-lookup/trunk/src/hbo.bash movie-lookup/trunk/src/lookup.bash Modified: movie-lookup/trunk/src/MovieLookup.scala =================================================================== --- movie-lookup/trunk/src/MovieLookup.scala 2007-12-25 02:09:09 UTC (rev 194) +++ movie-lookup/trunk/src/MovieLookup.scala 2007-12-25 04:47:07 UTC (rev 195) @@ -5,24 +5,43 @@ object MovieLookup { def main(args: Array[String]) { - val pairs = using (TextReader(args(0))) { r => - Set(( - for (line <- r.readLines) yield { - val parts = line.split("\\.\\.\\.\\.", 2) - (parts(1).split("\\.\\.+")(0), parts(0)) - } - ): _*) + // parse args + val schedFile = args(0) + val mode = args.length > 1 + + // read inputs + val scheduleLines = using (TextReader(schedFile)) (_.readLines.toArray) + val ratingLines = using (TextReader(System.in)) (_.readLines.toArray) + + // exhibit 1 of why java is useful + val sdf = new java.text.SimpleDateFormat("E, MMM d hh:mm a") + + // (title, time) + val titlesTimes = for (line <- scheduleLines) yield { + val parts = line.split("\\.\\.\\.\\.", 2) + (parts(1).split("\\.\\.+")(0), sdf parse parts(0)) } - // pairs.toList take 3 foreach println - val sdf = new java.text.SimpleDateFormat("E, MMM d hh:mm a") - val title2time = multimap(pairs toList) - using (TextReader(System.in)) { r => - for (line <- r.readLines) { + // title -> time + val title2time = multimap(titlesTimes toList) + + // (rating, title) + val titlesRatings = ratingLines map (_ split (" --- ",2)) map {case Array(x,y) => (y,x)} + // title -> rating + val title2rating = Map(titlesRatings: _*) withDefaultValue "" + + if (mode) { + // for each of the movies (which are presumably input in rating order), + // list out all their scheduled show times (chronologically) + for (((title,rating),line) <- titlesRatings zip ratingLines) { println(line) - //title2time(line.split(" --- ",2)(1)).toList foreach println - val xs = title2time(line.split(" --- ",2)(1)) /*map (_.split(" ",2)(0))*/ map sdf.parse toList; - xs sort (_.compareTo(_)< 0) map (" " + _) foreach println + title2time(title).toList sort (_.compareTo(_) < 0) map (" " + _) foreach println } + } else { + // print the same schedule that we read in, except now it's annotated + // with ratings + for (((title,time),line) <- titlesTimes zip scheduleLines) { + println(line + " --- " + title2rating(title)) + } } } } Modified: movie-lookup/trunk/src/hbo.bash =================================================================== --- movie-lookup/trunk/src/hbo.bash 2007-12-25 02:09:09 UTC (rev 194) +++ movie-lookup/trunk/src/hbo.bash 2007-12-25 04:47:07 UTC (rev 195) @@ -1,8 +1,9 @@ #!/usr/bin/env bash set -o errexit -o nounset +input=sample-hbo.txt -cat hbo.txt | +cat $input | sed 's/[^\.]*\.\.\.\.// ; s/\.\..*//' | sort -u | ./lookup.bash Modified: movie-lookup/trunk/src/lookup.bash =================================================================== --- movie-lookup/trunk/src/lookup.bash 2007-12-25 02:09:09 UTC (rev 194) +++ movie-lookup/trunk/src/lookup.bash 2007-12-25 04:47:07 UTC (rev 195) @@ -2,6 +2,8 @@ set -o errexit -o nounset +input=sample-hbo.txt + # get (cache) all the index pages (300-400 of these!) tmp="${TEMP:-/tmp}" @@ -19,6 +21,6 @@ # of the movies for which we have ratings, find their scheduled times fgrep ' --- ' "$ranked" | -scala -cp bin MovieLookup hbo.txt +scala -cp bin MovieLookup $input # vim:et:sw=2:ts=2 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |