weather.scala 590 B

123456789101112131415161718192021222324
  1. import scala.io._
  2. import scala.xml.{Source => Source2, _}
  3. import scala.actors._
  4. import Actor._
  5. def getWeatherInfo(woeid: String) = {
  6. val url = "http://weather.yahooapis.com/forecastrss?w=" + woeid
  7. val response = Source.fromURL(url).mkString
  8. val xmlResponse = XML.loadString(response)
  9. println(xmlResponse \\ "location" \\ "@city",
  10. xmlResponse \\ "condition" \\ "@temp")
  11. }
  12. val caller = self
  13. for(id <- 2391271 to 2391279) {
  14. actor{ getWeatherInfo(id.toString) }
  15. }
  16. for(id <- 2391271 to 2391279) {
  17. receiveWithin(5000) {
  18. case msg => println(msg)
  19. }
  20. }