Weather.js and Weather.cy

JavaScript library for weather in Cydgets.

Weather.js Weather.cy Back to Libraries

Getting started

These two files will allow you to get current weather with GPS from iOS weather.app, with ease.

Both libraries will ONLY work with Cydget Lockscreens. User must have LocationServices on and the weather.app set to current location. I use these scripts in all my weather cydgets. You can find them on http://junesiphone.com/supersecret

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="temp"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('temp').innerHTML = weather.temp(''); //returns current temp          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.temp('')

If var celsius is set to true, weather.temp('') will return the current temp in celcius. If var celsius is false weather.temp('') will return the current temp in fareinheit.

weather.temp('') can take one parameter a string. This string is added to end of the temp. Example if it is 24 degrees and you define weather.temp('& deg;'); without spaces it will return 24°. You can leave this blank just by doing weather.temp(''); The degree code is.

&deg;

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="temp"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('temp').innerHTML = weather.temp('&deg;'); //returns current temp + °          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.low('')

Returns the current low in either celsius or fareinheit depending on what var celcius is set to.

Takes one parameter just as weather.temp('').

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="low"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('low').innerHTML = weather.low('&deg;'); //returns current low + °          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.high('')

Returns the current high in either celsius or fareinheit depending on what var celcius is set to.

Takes one parameter just as weather.temp('').

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="high"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('high').innerHTML = weather.high('&deg;'); //returns current high + °          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.condition()

Returns the current weather condition number.

If you want it to return a condition word use in with an array of conditions.

var condition = ["Tornado", "Tropical Storm", ...];

You can also use it to choose a weather icon as it returns a number.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="condition"></div>
<img id="icon"/>

<!-- get weather -->
<script>
var condition = ["Tornado", "Tropical Storm", "Hurricane", "Thunderstorm", "Thunderstorm", "Snow", "Sleet", "Sleet", "Freezing Drizzle", "Drizzle", "Freezing Rain", "Showers", "Showers", "Flurries", "Snow", "Snow", "Snow", "Hail", "Sleet", "Dust", "Fog", "Haze", "Smoky", "Blustery", "Windy", "Cold", "Cloudy", "Cloudy", "Cloudy", "Cloudy", "Cloudy", "Clear", "Sunny", "Fair", "Fair", "Sleet", "Hot", "Thunderstorms", "Thunderstorms", "Thunderstorms", "Showers", "Heavy Snow", "Light Snow", "Heavy Snow", "Partly Cloudy", "Thunderstorm", "Snow", "Thunderstorm", "blank"];; // must declare celcius
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('condition').innerHTML = condition[weather.condition()] //returns current condition word          
};
document.getElementById('icon').src = 'img/' + weather.condition() + '.png' //this will get an image from the img folder since weather icons are usually numbered it will grab the current on for the current condition.          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.city()

Returns the current city name.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="city"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('city').innerHTML = weather.city(); //returns current city          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.humidity()

Returns the current humidity.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="humidity"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('humidity').innerHTML = weather.humidity(); //returns current humidity          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.windchill('')

Returns the current windchill.

Takes a string as a parameter just as weather.temp('');

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="windchill"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('windchill').innerHTML = weather.windchill(''); //returns current windchill          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.wind('')

Returns the current wind speed.

Takes a string as a parameter just as weather.temp('');

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="wind"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('wind').innerHTML = weather.wind(''); //returns current windspeed          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.direction()

Returns the current wind direction.

If the wind is 24 N weather.direction() will return N.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="direction"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('direction').innerHTML = weather.direction(); //returns current wind direction          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.visibility('')

Returns the current visibility.

Takes a string parameter just as weather.temp('');

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="visibility"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('visibility').innerHTML = weather.visibility(''); //returns current visibility          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.rain('')

Returns the current rain percentage.

Takes a string parameter just as weather.temp('');

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="rain"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('rain').innerHTML = weather.rain(''); //returns current rain percentage          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.dewpoint('')

Returns the current dewpoint.

Takes a string parameter just as weather.temp('');

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="dewpoint"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('dewpoint').innerHTML = weather.dewpoint(''); //returns current dewpoint          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.feelslike('')

Returns the current feelslike temp.

Takes a string parameter just as weather.temp('');

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="feelslike"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('feelslike').innerHTML = weather.feelslike(''); //returns current feelslike temp          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.sunset()

Returns the time sun will set.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="sunset"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('sunset').innerHTML = weather.sunset(); //returns current sunset          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.sunrise()

Returns the time sun will rise.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="sunrise"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('sunrise').innerHTML = weather.sunrise(); //returns current sunrise          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone

weather.updated()

Returns the last time weather was updated.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
<!--include weather.cy must include the type -->
<script type="text/cycript" src="js/weather.cy"></script>
<!--include weather.js below weather.cy -->
<script src="js/weather.js"></script>

<div id="updated"></div>

<!-- get weather -->
<script>
var celsius = true; // must declare celcius
var weatherdivs = function() { // must be named weatherdivs, this is the function that updates items on an interval
document.getElementById('updated').innerHTML = weather.updated(); //returns last update time          
};
weather.start(60000 * 15); //60000 * 15 determines how often it refreshes (15 minutes)
</script>
Tweet Libraries hosted with ❤ by JunesiPhone