Skip to content

Commit

Permalink
Merge branch 'background'
Browse files Browse the repository at this point in the history
  • Loading branch information
kunalkushwaha committed Jul 21, 2017
2 parents c444045 + f150341 commit 4d56dc3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
12 changes: 8 additions & 4 deletions src/Indicator.vala
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ public class Weather.Indicator : Wingpanel.Indicator {
}

private async void monitor_weather() {

var result = get_weather("",key);
display_widget.update_state(result.short_discription,result.temperature);

//Fetch Report every 30 Minutes
//TODO: Should be read from configuration file
get_weather("",key, display_widget);
GLib.Timeout.add_seconds (1800, () => {
get_weather("",key, display_widget);
return true;
},GLib.Priority.DEFAULT);
yield;
}

public void connections () {}
Expand Down
34 changes: 16 additions & 18 deletions src/lib/Weather.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ string get_ip(Soup.Session session) {

}

weatherInfo get_weather(string location, string secret_key) {
async void get_weather(string location, string secret_key, Weather.Widgets.DisplayWidget display_widget) {

//Init the session.
var session = new Soup.Session ();
Expand All @@ -27,40 +27,38 @@ string get_ip(Soup.Session session) {
string uri = "https://api.darksky.net/forecast/" + secret_key + "/";



// Get Location.
double lat, lon;
double lat=0, lon=0;
var query_location = new Soup.Message ("GET", loc_uri);
session.send_message (query_location);

try {
var parser = new Json.Parser();
var parser = new Json.Parser();

parser.load_from_data((string) query_location.response_body.flatten().data, -1);
parser.load_from_data((string) query_location.response_body.flatten().data, -1);

var root_object = parser.get_root().get_object();
lat = root_object.get_double_member("latitude");
lon = root_object.get_double_member("longitude");
var root_object = parser.get_root().get_object();
lat = root_object.get_double_member("latitude");
lon = root_object.get_double_member("longitude");
var city = root_object.get_string_member("city");

stderr.printf("Location : lat : %g, lon : %g \n", lat, lon);
stderr.printf("Location : City: %s \n", city);

}catch (Error e){
stderr.printf(" Unable to get location\n");
return info ;
stderr.printf(" Unable to get location\n");
// return;// info ;
}




var weather_uri = uri + lat.to_string() + "," + lon.to_string();
var message = new Soup.Message ("GET", weather_uri);
session.send_message (message);


try {
var parser = new Json.Parser ();

parser.load_from_data ((string) message.response_body.flatten().data, -1);

var root_object = parser.get_root ().get_object ();
Expand All @@ -71,12 +69,12 @@ string get_ip(Soup.Session session) {
stderr.printf("current : %s\n", summary);
info.short_discription = summary;
info.temperature = temp;

} catch (Error e) {
stderr.printf ("I guess something is not working... %s \n", e.message);
}

return info;

display_widget.update_state(info.short_discription,info.temperature);
return;
}

0 comments on commit 4d56dc3

Please sign in to comment.