Created
September 30, 2009 12:03
-
-
Save yuroyoro/198050 to your computer and use it in GitHub Desktop.
This file contains 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
import java.net.{URL,HttpURLConnection} | |
import java.io._ | |
object BijintDownloader extends Application{ | |
for( hour <- 0 to 23; minute <- 0 to 59){ | |
val fname = "%02d%02d.jpg".format( hour,minute ) | |
val url = "http://bijint.com/jp/img/clk/%s".format( fname ) | |
val urlConn = new URL(url).openConnection.asInstanceOf[HttpURLConnection] | |
urlConn.addRequestProperty("REFERER","http://bijint.com/jp/") | |
urlConn.connect | |
println( fname + ":" + urlConn.getResponseCode ) | |
val in = urlConn.getInputStream | |
val out = new BufferedOutputStream( new FileOutputStream( fname ) ) | |
val buf = Array.make( 1024 , (-1 ).toByte ) | |
def writeFile( len:Int ):Unit = { | |
if( len > 0 ) { | |
Thread.sleep( 10 ) | |
out.write( buf ) | |
writeFile( in.read( buf ) ) | |
} | |
} | |
writeFile( in.read( buf ) ) | |
out.flush | |
out.close | |
in.close | |
Thread.sleep( 1000 ) | |
println( "Download:" + fname ) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment