-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.html
More file actions
executable file
·122 lines (115 loc) · 3.46 KB
/
Copy pathclock.html
File metadata and controls
executable file
·122 lines (115 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<title>Polycom VVX écran de veille | widget </title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body,html{
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
table{
margin-top: -10px;
margin-left: -10px;
width: 100%; height: 100%; text-align: center;
}
td {
height: 100%; font-size:12px; vertical-align: middle;
}
</style>
</head>
<body>
<table >
<tr>
<td id="meteoWidget"></td>
<td id="dateWidget"></td>
</tr>
</table>
</body>
<script>
/**
* Id des conteneurs pour les widgets
*/
var meteoWidgetId = "meteoWidget";
var dateWidgetId = "dateWidget";
/**
* Pour changer la ville il faut changer l'id 'forecast?id=xxxxxxx' dans l'url.
* Pour trouver l'id chercher votre ville dans ce fichier http://bulk.openweathermap.org/sample/city.list.json.gz
* information provient de http://openweathermap.org/
*/
var weatherUrl = "http://api.openweathermap.org/data/2.5/forecast?id=6173017&appid=bafcefdeac8d50e4d3a7ef8aac9cc258&lang=fr&units=metric";
/**
* Initialise les widgets
*/
dateWidget();
meteoWidget();
/**
* Reload la date à toute les seconde
*/
setInterval(dateWidget, 1000);
/**
* Reload la meteo à toute les 15 minutes
*/
setInterval(meteoWidget, 1000 * 60 * 15);
/**
* Date Widget
*/
function dateWidget() {
var dayList = ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'];
var d = new Date();
var x = document.getElementById(dateWidgetId);
var weekDay = dayList[d.getDay()];
var date = addZero(d.getUTCDate());
var month = addZero(d.getUTCMonth());
var year = d.getFullYear();
var h = addZero(d.getHours());
var m = addZero(d.getMinutes());
var s = addZero(d.getSeconds());
x.innerHTML = weekDay + "<br>" + date + "-" + month + "-" + year + "<br>" + h + ":" + m + ":" + s;
}
/**
* Meteo Widget
*/
function meteoWidget() {
var weatherData = [];
getData(weatherUrl, function (data) {
weatherData.push(data);
console.log(weatherData[0]);
var location = weatherData[0].city;
var temperature = weatherData[0].list[0].main.temp;
var condition = weatherData[0].list[0].weather[0].description;
var content = location.name + '</br>';
content += Math.round(temperature) + '°' + 'c</br>';
content += condition;
document.getElementById(meteoWidgetId).innerHTML = content;
});
}
/**
* Execute l'appel Ajax
*/
function getData(weatherUrl, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var data = JSON.parse(xhr.responseText);
callback(data);
}
};
xhr.open('GET', weatherUrl, true);
xhr.send();
}
/**
* Ajoute un 0 sur le nombre contient seulement un chiffre
*/
function addZero(i) {
if (i < 10) {
i = "0" + i;
}
return i;
}
</script>
</html>