Skip to content

Instantly share code, notes, and snippets.

@favalos
Last active December 19, 2015 17:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save favalos/5988717 to your computer and use it in GitHub Desktop.
Save favalos/5988717 to your computer and use it in GitHub Desktop.
Added a companion object to read from http://feeds.bbci.co.uk/news/technology/rss.xml and run it.
class Feed(val url: String) {
def downloadItems(): List[Item] = {
val root = XML.load(url)
(root \\ "item").map(buildItem(_)).toList
}
def buildItem(node: Node): Item = {
new Item(this,
(node \\ "title").text,
(node \\ "guid").text,
(node \\ "pubDate").text)
}
}
class Item(
val parent: Feed,
val title: String,
val link: String,
val pubDate: String) {
override def toString(): String = {
"Title : " + title + " Link: " + link + " Date: " + pubDate
}
}
object Feed {
def main(args: Array[String]) = {
val feed = new Feed("http://feeds.bbci.co.uk/news/technology/rss.xml")
val feedList = feed.downloadItems
feedList.foreach(println)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment