[seed] Weather: Can pass zipcode on command line
- From: Tim Horton <hortont src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] Weather: Can pass zipcode on command line
- Date: Wed, 13 May 2009 21:46:26 -0400 (EDT)
commit 02d648416472f92be870b7784ff2e8d82107c353
Author: Tim Horton <hortont svn gnome org>
Date: Wed May 13 21:45:29 2009 -0400
Weather: Can pass zipcode on command line
---
examples/xml/weather.js | 23 +++++++++++++++++++++--
1 files changed, 21 insertions(+), 2 deletions(-)
diff --git a/examples/xml/weather.js b/examples/xml/weather.js
index c2bb2b4..352f033 100755
--- a/examples/xml/weather.js
+++ b/examples/xml/weather.js
@@ -6,6 +6,9 @@ readline = imports.readline;
var zipcode = "05446";
+if(Seed.argv[2])
+ zipcode = Seed.argv[2];
+
var session = new Soup.SessionSync();
// Soup.URI is a struct.
@@ -15,8 +18,24 @@ var status = session.send_message(request);
var data = request.response_body.data;
var doc = libxml.parseString(data);
-var ctx = doc.xpathNewContext()
+var ctx = doc.xpathNewContext();
ctx.xpathRegisterNs("yweather", "http://xml.weather.yahoo.com/ns/rss/1.0");
-Seed.print(ctx.xpathEval("//yweather:condition/@temp").value[0].content);
+var title = ctx.xpathEval("//item/title").value[0].content;
+
+var temp_unit = ctx.xpathEval("//yweather:units/@temperature").value[0].content;
+var distance_unit = ctx.xpathEval("//yweather:units/@distance").value[0].content;
+var pressure_unit = ctx.xpathEval("//yweather:units/@pressure").value[0].content;
+var speed_unit = ctx.xpathEval("//yweather:units/@speed").value[0].content;
+
+var temperature = ctx.xpathEval("//yweather:condition/@temp").value[0].content;
+var wind_chill = ctx.xpathEval("//yweather:wind/@chill").value[0].content;
+var wind_speed = ctx.xpathEval("//yweather:wind/@speed").value[0].content;
+var wind_direction = ctx.xpathEval("//yweather:wind/@speed").value[0].content;
+
+Seed.print(title);
+Seed.print("Temperature: " + temperature + " " + temp_unit +
+ " (wind chill: " + wind_chill + " " + temp_unit + ")");
+Seed.print("Wind: " + wind_speed + " " + speed_unit +
+ " @ " + wind_direction + " degrees");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]