Guest User

weather editor

a guest
Apr 29th, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //weather shamelessly stolen from Austin Kilduff
  2. var json_url = "http://api.openweathermap.org/data/2.5/weather?q=NewYork,ny&appid=6e131a2916d5d45d8367b72a4675be0a";
  3. var city;
  4. var temp_curr;
  5. var temp_low;
  6. var temp_high;
  7. var description;
  8. var weatherCode;
  9. var humidity;
  10. $.when(
  11.     $.getJSON(json_url)
  12.     ).done( function(json_obj) {
  13.         city = json_obj["name"];
  14.         temp_curr = k_to_f(json_obj["main"]["temp"]);
  15.         temp_low = k_to_f(json_obj["main"]["temp_min"]);
  16.         temp_high = k_to_f(json_obj["main"]["temp_max"]);
  17.         description = json_obj["weather"][0]["description"];
  18.         weatherCode = Number(json_obj["weather"][0]["id"]);
  19.         humidity = Number(json_obj["main"]["humidity"])
  20.         insertWeatherInfo();
  21.     }
  22. );
  23. function k_to_f(kelvin) {
  24.     return ((9 / 5) * (kelvin - 273) + 32).toFixed(0);
  25. }
  26. function insertWeatherInfo() {
  27.     //$("#city").append(city.toLowerCase());
  28.     $("#description").append(description.toLowerCase());
  29.     $("#temp_curr").prepend("it's " + temp_curr + "° out");
  30.     $("#temp_low").append("lo " + temp_low + "° /");
  31.     $("#temp_high").append("hi " + temp_high + "°");
  32.     console.log("weather code: " + weatherCode);
  33.     console.log("humidity: " + humidity);
  34.     var disgusting = (weatherCode > 500 && weatherCode < 800);
  35.     if (disgusting || Number(temp_low) < 30 || Number(temp_high) > 95
  36.         || humidity > 75) {
  37.         $("#badness").append("disgusting");
  38.     } else {
  39.         $("#badness").append("not bad");
  40.     }
  41. }
  42.  
  43.  
  44. var monthNames = [
  45.   "January", "February", "March",
  46.   "April", "May", "June", "July",
  47.   "August", "September", "October",
  48.   "November", "December"
  49. ];
  50. var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
  51.  
  52. var date = new Date();
  53. var day = date.getDate();
  54. var weekday = date.getDay();
  55. var monthIndex = date.getMonth();
  56. var year = date.getFullYear();
  57.  
  58. document.getElementById("date").innerHTML = days[weekday] + ", " + monthNames[monthIndex] + " " + day;
Advertisement
Add Comment
Please, Sign In to add comment