- プログラミング言語 Scala 10冊目
233 :デフォルトの名無しさん[sage]:2014/03/29(土) 15:15:02.64 ID:iSspUegM - import java.io.File
import java.net.URL import org.apache.commons.io.{FileUtils, FilenameUtils} val urlRe = """(?i)h?ttps?://[\w/:%#\$&\?\(\)~\.=\+\-]+\.(jpg|jpeg|png|bmp)""".r val imgDir = new File("img") val encoding = "Shift_JIS" def エロ画像収集(url: String) = { if (!dir.exists()) dir.mkdir() val urls = io.Source.fromURL(url, encoding).mkString.split("\n").map(s => urlRe.findAllIn(s).toList).flatten val fixedUrls = urls.map(s => if (s.startsWith("ttp")) "h" + s else s) fixedUrls.par.foreach{ url => def recur(n: Int): Unit = { val name = FilenameUtils.getName(url) val file = new File(imgDir, + name) try { if (!file.exists()) FileUtils.copyURLToFile(new URL(url), file) } catch { case e: java.io.FileNotFoundException => case e: java.io.IOException => if (n < 3) { java.lang.Thread.sleep(3000) recur(n + 1) } } } recur(0) } } def test_エロ画像収集() = エロ画像収集("""http://pele.bbspink.com/test/read.cgi/ascii2d/1394675699/""")
| - プログラミング言語 Scala 10冊目
234 :ver2[sage]:2014/03/29(土) 15:31:22.62 ID:iSspUegM - import java.io.{File, FileNotFoundException, IOException}
import java.net.URL import java.lang.Thread import org.apache.commons.io.{FileUtils, FilenameUtils} import java.util.concurrent.atomic.AtomicInteger val urlRe = """(?i)h?ttps?://[\w/:%#\$&\?\(\)~\.=\+\-]+\.(jpg|jpeg|png|bmp)""".r val imgDir = new File("img") val encoding = "Shift_JIS" val count = new AtomicInteger() def エロ画像収集(url: String) = { if (!dir.exists()) dir.mkdir() val urls = io.Source.fromURL(url, encoding).mkString.split("\n").map(s => urlRe.findAllIn(s).toList).flatten val fixedUrls = urls.map(s => if (s.startsWith("ttp")) "h" + s else s).distinct fixedUrls.par.foreach{ url => def recur(n: Int): Unit = { val ext = FilenameUtils.getExtension(url) val file = new File(imgDir, count.incrementAndGet().toString + "." + ext) try { if (!file.exists()) FileUtils.copyURLToFile(new URL(url), file) } catch { case e: FileNotFoundException => case e: IOException => if (n < 3) { java.lang.Thread.sleep(3000) recur(n + 1) } } } recur(0) } } def test_エロ画像収集() = エロ画像収集("http://pele.bbspink.com/test/read.cgi/ascii2d/1394675699/")
| - C++は難しすぎ 難易度:4
481 :デフォルトの名無しさん[sage]:2014/03/29(土) 16:53:38.29 ID:iSspUegM - test
| - プログラミング言語 Scala 10冊目
236 :ver3[sage]:2014/03/29(土) 23:39:16.57 ID:iSspUegM - import java.io.{File, FileNotFoundException, IOException}
import java.net.URL import java.lang.Thread import org.apache.commons.io.{FileUtils, FilenameUtils} val urlRe = """(?i)h?ttps?://[\w/:%#\$&\?\(\)~\.=\+\-]+\.(jpg|jpeg|png|bmp)""".r val imgDir = new File("img") def エロ画像収集(url: String) = { if (!dir.exists()) dir.mkdir() val urls = io.Source.fromURL(url, "Shift_JIS").getLines.map(s => urlRe.findAllIn(s)).flatten.toList val fixedUrls = urls.map(s => if (s.startsWith("ttp")) "h" + s else s).distinct fixedUrls.par.foreach{ url => def recur(n: Int): Unit = { val ext = FilenameUtils.getExtension(url) val file = new File(imgDir, url.replaceAll("[^a-zA-Z0-9]","") + "." + ext) try { if (!file.exists()) FileUtils.copyURLToFile(new URL(url), file) } catch { case e: FileNotFoundException => case e: IOException => if (n < 3) { Thread.sleep(3000) recur(n + 1) } } } recur(0) } }
|
|