Created
January 3, 2012 13:33
-
-
Save nergal/1554897 to your computer and use it in GitHub Desktop.
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
import java.net.{URLConnection,URL} | |
import scala.xml._ | |
import scala.collection.mutable.Buffer | |
case class Feed(val url: String) { | |
var buff: Elem = { | |
val u = new URL(this.url) | |
val conn = u.openConnection() | |
conn.connect | |
XML.load(conn.getInputStream) | |
} | |
private def nice(str: Elem): String = { | |
var res: Buffer[String] = Buffer() | |
for (item <- str\"channel"\"item") { | |
val Array(cat, title) = (item\"title").last.text.split("/", 2).map(_ trim) | |
val link = (item\"link").last.text | |
var rec: String = "Category: %s\nTitle: %s\nLink: %s\n\n".format(cat, title, link) | |
res+= rec | |
} | |
res.mkString | |
} | |
override def toString(): String = { | |
this.nice(buff) | |
} | |
} | |
val xml = new Feed("http://habrahabr.ru/rss/best/") | |
println(xml) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment