Skip to content

Instantly share code, notes, and snippets.

@jorpic
Last active January 5, 2016 12:25
Show Gist options
  • Save jorpic/7c4aa434b8a7dfb3c574 to your computer and use it in GitHub Desktop.
Save jorpic/7c4aa434b8a7dfb3c574 to your computer and use it in GitHub Desktop.
Weather in Moscow
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<link href="http://fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">
<style>
body {
margin: 0;
font-family: "Raleway", Helvetica, sans-serif;
color: #313;
text-align: center;
}
#time {
font-size: small;
font-weight: lighter;
}
@media screen {
body {font-size: 10vmin;}
#time {font-size: 2vmin; }
}
</style>
</head>
<body>
<h1 id="city"></h1>
<h2 id="temp"></h2>
<span id="time">Please wait a bit...</span>
<script>
'use strict';
function setTextContent(id, txt) {
document.getElementById(id).textContent = txt;
}
function render(dat) {
setTextContent('city', dat.name);
setTextContent('temp', Math.round(dat.main.temp) + '°C');
setTextContent('time', 'Updated at ' + new Date().toLocaleTimeString('ru-RU'));
}
var api = 'http://api.openweathermap.org/data/2.5/weather';
var url = api + '?q=Moscow,ru&units=metric';
function update() {
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = function (){render(JSON.parse(this.responseText))};
xhr.send(null);
}
update();
setInterval(update, 30*1000);
</script>
</body>
</html>
@jorpic
Copy link
Author

jorpic commented Jan 5, 2016

Does not work now. Seems openweathermap.org disabled CORS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment