Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuroyoro/198050 to your computer and use it in GitHub Desktop.
Save yuroyoro/198050 to your computer and use it in GitHub Desktop.
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