Created
February 15, 2012 20:23
-
-
Save ThomasAlexandre/1838767 to your computer and use it in GitHub Desktop.
JFokus 2012 v1 - sample from "One liners are your friend"
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
Http(url("http://api.groupon.com/v2/divisions.xml?client_id=<your_client_id>") >>> System.out) | |
Http(url("http://api.groupon.com/v2/divisions.xml?client_id=<your_client_id>") as_str) | |
val grouponCitiesURL = url("http://api.groupon.com/v2/divisions.xml?client_id=<your_client_id>") | |
Http(grouponCitiesURL as_str) | |
val citiesAsXML = Http(grouponCitiesURL <> { response => response \\ "division" }) | |
val cityNames = citiesAsXML map ( city => (city \ "name").text ) | |
val cityNames = citiesAsXML map ( city => (city \ "name").text ) filter(_.startsWith("H")) | |
val cityLocations = citiesAsXML map { city => ((city \ "name").text,(city \ "lat").text,(city \ "lng").text) } | |
cityLocations find (location => location._1 == "Honolulu") | |
cityLocations find (_._1 == "Honolulu") | |
cityLocations find (_._1 == "Honoulu") | |
val (honolulu,lat,lng) = cityLocations find (_._1 == "Honolulu") getOrElse("Honolulu","21","-157") | |
val dealsURL = url("http://api.groupon.com/v2/deals.xml?client_id=<your_client_id>") | |
val deals = Http(dealsURL <<? Map("lat"->lat,"lng"->lng) as_str) | |
case class Deal(title:String = "", dealUrl:String = "", tag:String = "") | |
val deals = Http(dealsURL <<? Map("lat"->lat, "lng"->lng) <> { xml => xml \\ "deal" map (deal => Deal((deal \\ "title").text,(deal \\ "dealUrl").text,(deal \\ "tag").text)) }) | |
val deals = Http(dealsURL <<? Map("lat"->lat, "lng"->lng) <> { xml => | |
for ( deal <- xml \\ "deal"; | |
title = (deal \\ "title").text; | |
dealUrl = (deal \\ "dealUrl").text; | |
tag = (deal \\ "tag" \ "name").text) yield Deal(title,dealUrl,tag) }) | |
deals.size | |
val sortedDeals = deals groupBy(_.tag) | |
sortedDeals.keys.size | |
val nbOfDealsPerTag = sortedDeals mapValues(_.size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment