Skip to content

Instantly share code, notes, and snippets.

@gedankenstuecke
Last active January 4, 2019 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gedankenstuecke/642fa35ffa0a5921a18a3ca3af0b658e to your computer and use it in GitHub Desktop.
Save gedankenstuecke/642fa35ffa0a5921a18a3ca3af0b658e to your computer and use it in GitHub Desktop.
javascript used for the personalapi display
$(function(){
var json_url = $('#json_url').attr('href');
$.get(json_url, function(data){
if(data.location.tz){
var local_time = new Date( new Date().getTime() + data.location.tz_offset * 1000).toUTCString().replace( / GMT$/, "" ).substring(17,22);
$("#local_time").html(local_time);
$("#time_zone").html(data.location.tz);
$("#time_info").removeClass('invisible');
};
if(data.location.place){
$("#location_name").html(data.location.place);
$("#flag").attr("src", data.location.flag_url);
$("#location_info").removeClass('invisible');
};
if(data.location.weather){
$("#weather_condition").html(data.location.weather.condition_text);
$("#weather_temperature").html(data.location.weather.temperature_outside);
$("#condition_icon").attr("class", "wi wi-owm-" + data.location.weather.code);
$("#weather").removeClass('invisible');
}
if(data.activity.heart_rate){
$("#heart_rate").html(data.activity.heart_rate);
$("#steps").html(data.activity.steps);
$("#sleep").html(data.activity.hours_slept);
var battery_level = data.location.battery_level*100;
if(battery_level<10){
$("#battery_icon").attr("class", "fas fa-battery-empty");
} else if (battery_level < 30){
$("#battery_icon").attr("class", "fas fa-battery-quarter");
} else if (battery_level < 60){
console.log('battery_should_be_half');
$("#battery_icon").attr("class", "fas fa-battery-half");
} else if (battery_level < 85){
$("#battery_icon").attr("class", "fas fa-battery-three-quarters");
} else {
$("#battery_icon").attr("class", "fas fa-battery-full");
};
$("#battery_level").html(Math.floor(battery_level));
$("#battery_state").html(data.location.battery_state);
$("#activity_info").removeClass('invisible');
};
if(data.music){
$("#title").html(data.music.title);
$("#artist").html(data.music.artist);
$("#music_info").removeClass('invisible');
};
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment