You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Second, OpenWeather's API changed so you need an API key now. Unfortunately, at least from my testing, the API does not return the same results as displayed in Chapter 6 making those sections/exercises difficult to understand what is supposed to be happening.
In chapter 7 it appears to work if I manually call cityTempe, but otherwise the code itself as written doesn't appear to execute. If I call cityTemp("Scottsdale") and hit save multiple times within the Eclipse IDE or command line, it will show up eventually every fifth or sixth time.
def cityTemp(name: String): Double = {
val url = "http://api.openweathermap.org/data/2.5/weather?appid=[APIKEY]"
val cityUrl = s"$url&q=$name"
val json = io.Source.fromURL(cityUrl).mkString.trim
val pattern = """.*"temp":([\d.]+).*""".r
val pattern(temp) = json
temp.toDouble
} //> cityTemp: (name: String)Double
val cityTemps = Future sequence Seq(
Future(cityTemp("Fresno")), Future(cityTemp("Tempe"))
) //> cityTemps : scala.concurrent.Future[Seq[Double]] = List()
cityTemps onSuccess {
case Seq(x,y) if x > y => println(s"Fresno is warmer: $x K")
case Seq(x,y) if x < y => println(s"Tempe is warmer: $y K")
}
Thoughts?
The text was updated successfully, but these errors were encountered:
Hello,
First off, great book.
Second, OpenWeather's API changed so you need an API key now. Unfortunately, at least from my testing, the API does not return the same results as displayed in Chapter 6 making those sections/exercises difficult to understand what is supposed to be happening.
In chapter 7 it appears to work if I manually call cityTempe, but otherwise the code itself as written doesn't appear to execute. If I call
cityTemp("Scottsdale")
and hit save multiple times within the Eclipse IDE or command line, it will show up eventually every fifth or sixth time.Thoughts?
The text was updated successfully, but these errors were encountered: