Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //weather shamelessly stolen from Austin Kilduff
- var json_url = "http://api.openweathermap.org/data/2.5/weather?q=NewYork,ny&appid=6e131a2916d5d45d8367b72a4675be0a";
- var city;
- var temp_curr;
- var temp_low;
- var temp_high;
- var description;
- var weatherCode;
- var humidity;
- $.when(
- $.getJSON(json_url)
- ).done( function(json_obj) {
- city = json_obj["name"];
- temp_curr = k_to_f(json_obj["main"]["temp"]);
- temp_low = k_to_f(json_obj["main"]["temp_min"]);
- temp_high = k_to_f(json_obj["main"]["temp_max"]);
- description = json_obj["weather"][0]["description"];
- weatherCode = Number(json_obj["weather"][0]["id"]);
- humidity = Number(json_obj["main"]["humidity"])
- insertWeatherInfo();
- }
- );
- function k_to_f(kelvin) {
- return ((9 / 5) * (kelvin - 273) + 32).toFixed(0);
- }
- function insertWeatherInfo() {
- //$("#city").append(city.toLowerCase());
- $("#description").append(description.toLowerCase());
- $("#temp_curr").prepend("it's " + temp_curr + "° out");
- $("#temp_low").append("lo " + temp_low + "° /");
- $("#temp_high").append("hi " + temp_high + "°");
- console.log("weather code: " + weatherCode);
- console.log("humidity: " + humidity);
- var disgusting = (weatherCode > 500 && weatherCode < 800);
- if (disgusting || Number(temp_low) < 30 || Number(temp_high) > 95
- || humidity > 75) {
- $("#badness").append("disgusting");
- } else {
- $("#badness").append("not bad");
- }
- }
- var monthNames = [
- "January", "February", "March",
- "April", "May", "June", "July",
- "August", "September", "October",
- "November", "December"
- ];
- var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
- var date = new Date();
- var day = date.getDate();
- var weekday = date.getDay();
- var monthIndex = date.getMonth();
- var year = date.getFullYear();
- document.getElementById("date").innerHTML = days[weekday] + ", " + monthNames[monthIndex] + " " + day;
Advertisement
Add Comment
Please, Sign In to add comment