Created
April 16, 2013 20:32
-
-
Save rickeyvisinski-kanban/5399383 to your computer and use it in GitHub Desktop.
The second for loop will never be evaluated unless links in explicitly resolved, eg val nl = links()...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test | |
import dispatch._ | |
import scala.collection.JavaConverters._ | |
import java.io.{ FileOutputStream, File } | |
import org.apache.commons.io.IOUtils | |
import scala.concurrent.ExecutionContext.Implicits.global | |
object App { | |
val URL = "http://flickr.com/explore" | |
def mkUrl(u:String) = url(u) | |
def wrOut(ab:Array[Byte], nm:String):Unit = { | |
IOUtils.write(ab, new FileOutputStream(new File("/tmp/" + nm))) | |
} | |
def fetchByte(u:String) = Http(mkUrl(u) OK as.Bytes) | |
def main(args:Array[String]) { | |
println("starting...") | |
val reqf = Http(mkUrl(URL) OK as.jsoup.Document) | |
val links = for { | |
req <- reqf | |
} | |
yield req.select("img[src$=.jpg]").asScala.toList | |
for { | |
lel <- links | |
ts <- lel | |
} { | |
val nm = ts.text | |
println(nm) | |
val link = ts.attr("src") | |
val nr = fetchByte(link) | |
for (r <- nr) wrOut(r, nm) | |
} | |
println("nothing was evaluated...") | |
Thread.sleep(5000) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment