@@ -16,7 +16,7 @@ string get_ip(Soup.Session session) {
1616
1717}
1818
19- weatherInfo get_weather(string location, string secret_key) {
19+ async void get_weather(string location, string secret_key, Weather . Widgets . DisplayWidget display_widget ) {
2020
2121 // Init the session.
2222 var session = new Soup .Session ();
@@ -27,40 +27,38 @@ string get_ip(Soup.Session session) {
2727 string uri = " https://api.darksky.net/forecast/" + secret_key + " /" ;
2828
2929
30-
3130 // Get Location.
32- double lat, lon;
31+ double lat= 0 , lon= 0 ;
3332 var query_location = new Soup .Message (" GET" , loc_uri);
3433 session. send_message (query_location);
3534
3635 try {
37- var parser = new Json .Parser ();
36+ var parser = new Json .Parser ();
3837
39- parser. load_from_data((string ) query_location. response_body. flatten(). data, - 1 );
38+ parser. load_from_data((string ) query_location. response_body. flatten(). data, - 1 );
4039
41- var root_object = parser. get_root(). get_object();
42- lat = root_object. get_double_member(" latitude" );
43- lon = root_object. get_double_member(" longitude" );
40+ var root_object = parser. get_root(). get_object();
41+ lat = root_object. get_double_member(" latitude" );
42+ lon = root_object. get_double_member(" longitude" );
4443 var city = root_object. get_string_member(" city" );
4544
4645 stderr. printf(" Location : lat : %g , lon : %g \n " , lat, lon);
4746 stderr. printf(" Location : City: %s \n " , city);
4847
4948 }catch (Error e){
50- stderr. printf(" Unable to get location\n " );
51- return info ;
49+ stderr. printf(" Unable to get location\n " );
50+ // return;// info ;
5251 }
53-
54-
52+
5553
5654 var weather_uri = uri + lat. to_string() + " ," + lon. to_string();
5755 var message = new Soup .Message (" GET" , weather_uri);
5856 session. send_message (message);
5957
60-
58+
6159 try {
6260 var parser = new Json .Parser ();
63-
61+
6462 parser. load_from_data ((string ) message. response_body. flatten(). data, - 1 );
6563
6664 var root_object = parser. get_root (). get_object ();
@@ -71,12 +69,12 @@ string get_ip(Soup.Session session) {
7169 stderr. printf(" current : %s\n " , summary);
7270 info. short_discription = summary;
7371 info. temperature = temp;
74-
72+
7573
7674 } catch (Error e) {
7775 stderr. printf (" I guess something is not working... %s \n " , e. message);
7876 }
79-
80- return info;
81-
77+ display_widget . update_state(info . short_discription,info . temperature);
78+
79+ return ;
8280}
0 commit comments