-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
146 lines (136 loc) · 5.86 KB
/
index.html
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Sometype+Mono:wght@400;700&display=swap" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> -->
<script src="skycons.js"></script>
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="refresh" content="1800">
<style>
body {
font-family: "Sometype Mono", sans-serif;
background-color: #000;
color: #fff;
line-height: 1;
font-size: 65px;
margin: 0;
}
p { margin: 0; }
#container { width: 100%; }
#left, #right {
float: left;
width: 50%;
text-align: center;
}
#left {
margin-top: 25vh;
}
#right { text-align: right; }
.day p { display: inline-block; margin-right: 10px; }
/* canvas { margin-top: 20px; } */
#time, #current-temp {
font-weight: 500;
font-size: 168px;
}
span[id^="minTemp"] {
opacity: 0.5;
}
[id^="minTemp"]::after {
content: "•";
margin-left: 0.5em;
font-size: 0.5em;
vertical-align: middle;
} </style>
<script>
$(document).ready(function() {
var url = 'https://api.open-meteo.com/v1/forecast?latitude=37.7646489&longitude=-122.4647699¤t=temperature_2m&hourly=temperature_2m&daily=weather_code,temperature_2m_max,temperature_2m_min&temperature_unit=fahrenheit&wind_speed_unit=ms&precipitation_unit=inch&timezone=America%2FLos_Angeles';
var skycons = new Skycons({"color": "white"});
function getSkycon(weatherCode) {
const skyconMap = {
0: Skycons.CLEAR_DAY,
1: Skycons.PARTLY_CLOUDY_DAY,
2: Skycons.PARTLY_CLOUDY_DAY,
3: Skycons.CLOUDY,
51: Skycons.RAIN,
53: Skycons.RAIN,
55: Skycons.RAIN,
61: Skycons.RAIN,
63: Skycons.RAIN,
65: Skycons.RAIN,
80: Skycons.RAIN,
81: Skycons.RAIN,
82: Skycons.RAIN,
56: Skycons.SLEET,
57: Skycons.SLEET,
66: Skycons.SLEET,
67: Skycons.SLEET,
71: Skycons.SNOW,
73: Skycons.SNOW,
75: Skycons.SNOW,
77: Skycons.SNOW,
85: Skycons.SNOW,
86: Skycons.SNOW,
45: Skycons.FOG,
48: Skycons.FOG
};
return skyconMap[weatherCode] || Skycons.CLOUDY;
}
function formatDateTime() {
var now = new Date();
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var day = days[now.getDay()];
var date = now.getDate();
var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var month = months[now.getMonth()];
var hours = now.getHours();
var minutes = now.getMinutes() < 10 ? '0' + now.getMinutes() : now.getMinutes();
return day + ' ' + month + ' ' + date + ', ' + hours + ':' + minutes;
}
function updateDateTime() {
$('#date').html(formatDateTime().split(',')[0].toLowerCase());
$('#time').html(formatDateTime().split(',')[1]);
}
setInterval(updateDateTime, 1000);
function forecast() {
$.getJSON(url, function(data) {
console.log("Data received:", data);
$('#current-temp').html(Math.round(data.current.temperature_2m) + '°F');
for (var i = 0; i < data.daily.time.length; i++) {
var weatherCode = data.daily.weather_code[i];
var skyconType = getSkycon(weatherCode);
skycons.set('day' + i, skyconType);
var maxTemp = data.daily.temperature_2m_max[i];
console.log(maxTemp);
$('#temp' + i).html(Math.round(data.daily.temperature_2m_max[i]) + '°F');
}
skycons.play();
}).fail(function(jqXHR, textStatus, errorThrown) {
// console.error("Error fetching data:", textStatus, errorThrown); // Log any errors
console.log("Detailed error information:", jqXHR);
});
setTimeout(forecast, 120000); // Re-run every 2 minutes
}
forecast();
});
</script>
</head>
<body>
<div id="container">
<div id="left">
<p id="date"></p>
<p id="time"></p>
<p id="current-temp"></p>
</div>
<div id="right">
<p id="temp0"></p><canvas width="100" height="100" id="day0"></canvas>
<p id="temp1"></p><canvas width="100" height="100" id="day1"></canvas>
<p id="temp2"></p><canvas width="100" height="100" id="day2"></canvas>
<p id="temp3"></p><canvas width="100" height="100" id="day3"></canvas>
<p id="temp4"></p><canvas width="100" height="100" id="day4"></canvas>
<p id="temp5"></p><canvas width="100" height="100" id="day5"></canvas>
<p id="temp6"></p><canvas width="100" height="100" id="day6"></canvas>
</div>
</div>
</body>
</html>