Last active
December 19, 2015 17:08
-
-
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.
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
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