10
string current_content;
13
public string[] get_attributes (string data, string tagname, string [] attrs, int offset = 0)
15
var start = data.index_of ("<" + tagname, offset) + tagname.length + 1;
16
var end = data.index_of ("/>", start);
17
var tmp_data = data.substring (start, end - start);
19
var res = new string[attrs.length];
20
for (var i = 0; i < attrs.length; i++) {
21
res[i] = get_attribute_value (tmp_data, attrs[i]);
26
public string get_attribute_value (string data, string attr)
28
var start = data.index_of (attr + "=\"") + attr.length + 2;
29
var end = data.index_of ("\"", start);
31
return data.substring (start, end - start);
38
const string [] condition_codes = {
40
"0", // tropical storm
42
"1", // severe thunderstorms
44
"2", // mixed rain and snow
45
"3", // mixed rain and sleet
46
"2", // mixed snow and sleet
47
"e", // freezing drizzle
53
"G", // light snow showers G
54
"#", // blowing snow #
66
"4", // mostly cloudy (night) 4
67
"3", // mostly cloudy (day) 3
68
"K", // partly cloudy (night) K
69
"J", // partly cloudy (day) J
70
"C", // clear (night) C
72
"2", // fair (night) 2
74
"X", // mixed rain and hail X
76
"1", // isolated thunderstorms
77
"1", // scattered thunderstorms
78
"1", // scattered thunderstorms
79
"e", // scattered showers
81
"2", // scattered snow showers
83
"H", // partly cloudy H
84
"1", // thundershowers
86
"1", // isolated thundershowers
87
")" // not available )
10
92
var settings = new Settings ("org.pantheon.gazette.weather");
22
104
url += "?u=" + unit;
24
106
url += "&w=" + id;
26
var session = new Soup.SessionSync ();
108
var session = new Soup.SessionAsync ();
27
109
var message = new Soup.Message ("GET", url);
29
session.send_message (message);
31
var output = (string)message.response_body.data;
33
var start = output.index_of ("text=\"") + 6;
34
text = output.substring (start, output.index_of ("\"", start) - start);
35
start = output.index_of ("temp=\"") + 6;
36
temp = output.substring (start, output.index_of ("\"", start) - start);
112
session.queue_message (message, (session, m) => {
113
var data = (string)m.response_body.data;
114
var current = get_attributes (data, "yweather:condition", {"temp", "text", "code"});
115
var forecast = get_attributes (data, "yweather:forecast", {"day", "date", "low", "high", "text", "code"});
116
var forecast2 = get_attributes (data, "yweather:forecast", {"day", "date", "low", "high", "text", "code"},
117
data.index_of ("<yweather:forecast") + 20);
119
current_content = "<span face='gazetteweather' font='42'>" + condition_codes[int.parse (current[2])] + "</span>" +
120
"<span face='Open Sans Light' font='24'> " + current[1] +"</span>\n" +
121
"<span face='Raleway' weight='100' font='72'>" + current[0] + "</span>";
122
for_content = "<span face='gazetteweather' font='30'>" + condition_codes[int.parse (forecast[5])] + "</span>" +
123
"<span face='Open Sans Light' font='26'> " + forecast[0] + "</span>\n" +
124
"<span face='Open Sans Light' font='16'>" + forecast[4] + "</span>\n" +
125
"<span face='Raleway' font='32' weight='200'>" + forecast[2] + " - " + forecast[3] + "</span>" +
126
"<span face='gazetteweather' font='30'>" + condition_codes[int.parse (forecast2[5])] + "</span>" +
127
"<span face='Open Sans Light' font='26'> " + forecast2[0] + "</span>\n" +
128
"<span face='Open Sans Light' font='16'>" + forecast2[4] + "</span>\n" +
129
"<span face='Raleway' font='32' weight='200'>" + forecast2[2] + " - " + forecast2[3] + "</span>";
134
cur.x = Math.floorf (width / 2 - cur.width / 2);
40
138
public override void create ()
52
var label = new ShadowedLabel ("<span font='20' face='Raleway'>%s</span>".printf (_("Your Local Weather")+"\n")+
53
"<span face='Open Sans Light' font='52'>☔</span>"+
151
var label = new ShadowedLabel ("<span font='20' face='Raleway'>%s</span>".printf (_("Your Local Weather"+"\n"))+
54
152
"<span face='Open Sans Light' font='24'><i>"+text+"</i></span>\n"+
55
"<span face='Raleway' font='72'> "+temp+"°"+unit+"</span>");
153
"<span face='Raleway' font='72'> "+current_content+"°"+unit
56
156
add_child (label);