-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex_modern.html
246 lines (217 loc) · 9.1 KB
/
index_modern.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css2?family=Sometype+Mono:wght@400;700&display=swap" rel="stylesheet">
<script src="skycons.js"></script>
<meta name="apple-mobile-web-app-capable" content="yes">
<style>
/* General styles */
body {
font-family: "Sometype Mono";
background-color: #000;
color: #fff;
/* font-weight: 300; */
line-height: 1;
font-size: 65px;
margin: 0;
display: flex;
flex-direction: column;
height: 100vh;
justify-content: center;
}
p {
margin: 0;
}
#container {
display: flex;
justify-content: space-between;
align-items: center;
width: 100%;
}
#left, #right, .day {
display: flex;
flex-direction: column;
align-items: center;
}
#left {
flex: 1;
text-align: center;
}
#right {
flex: 0.5;
align-items: flex-end;
}
.day {
flex-direction: row;
}
/* canvas {
margin-top: 20px;
} */
#time {
font-weight: 500;
font-size: 168px;
}
#current-temp {
font-size: 100px;
margin-top: 100px;
font-weight: 500;
}
#time {
font-weight: 500;
font-size: 168px;
}
p[id="temp0"] {
font-size: 100px;
font-weight: 500;
margin-bottom: 50px;
}
#current-temp {
font-size: 100px;
margin-top: 100px;
font-weight: 500;
}
span[id^="minTemp"] {
opacity: 50%;
}
[id^="minTemp"]::after {
content: "•"; /* Unicode character for a bullet */
margin-left: 0.5em; /* Space before the bullet */
font-size: 0.5em; /* Smaller size for the bullet */
vertical-align: middle; /* Aligns the bullet with the middle of the text */
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {
const 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'
const 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; // Default to CLOUDY if code not found
}
// update the date and time every 1000ms
function updateDateTime() {
const date = new Date();
const dayNames = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
const monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const day = dayNames[date.getDay()];
const month = monthNames[date.getMonth()];
const dayOfMonth = date.getDate();
document.getElementById('date').innerHTML = `${day}, ${month} ${dayOfMonth}`;
document.getElementById('time').innerHTML = date.toLocaleTimeString([], {hour: '2-digit', minute:'2-digit'});
}
setInterval(updateDateTime, 1000);
// async function to fetch weather, run every 120000ms, also call on first load
async function fetchWeather() {
try {
const response = await fetch(url);
const data = await response.json();
console.log(data);
// Set current temperature
document.getElementById('current-temp').textContent = Math.round(data.current.temperature_2m) + '°F';
// Set Skycons and temperatures for each day
data.daily.time.forEach((time, index) => {
const weatherCode = data.daily.weather_code[index];
const skyconType = getSkycon(weatherCode);
skycons.set(`canvas${index}`, skyconType);
const maxTemp = data.daily.temperature_2m_max[index];
const minTemp = data.daily.temperature_2m_min[index];
document.getElementById(`maxTemp${index}`).textContent = `${Math.round(data.daily.temperature_2m_max[index])}°F`;
document.getElementById(`minTemp${index}`).textContent = `${Math.round(data.daily.temperature_2m_min[index])}°F`;
});
skycons.play();
} catch (error) {
console.error('Error fetching weather data:', error);
}
}
fetchWeather();
setInterval(fetchWeather, 120000);
});
</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">
<div class="day">
<p id="day0">
<span id="minTemp0"></span>
<span id="maxTemp0"></span>
</p>
<canvas width="100" height="100" id="canvas0"></canvas>
</div>
<div class="day">
<p id="day1">
<span id="minTemp1"></span>
<span id="maxTemp1"></span>
</p>
<canvas width="100" height="100" id="canvas1"></canvas>
</div>
<div class="day">
<p id="day2">
<span id="minTemp2"></span>
<span id="maxTemp2"></span>
</p>
<canvas width="100" height="100" id="canvas2"></canvas>
</div>
<div class="day">
<p id="day3">
<span id="minTemp3"></span>
<span id="maxTemp3"></span>
</p>
<canvas width="100" height="100" id="canvas3"></canvas>
</div>
<div class="day">
<p id="day4">
<span id="minTemp4"></span>
<span id="maxTemp4"></span>
</p>
<canvas width="100" height="100" id="canvas4"></canvas>
</div>
<div class="day">
<p id="day5">
<span id="minTemp5"></span>
<span id="maxTemp5"></span>
</p>
<canvas width="100" height="100" id="canvas5"></canvas>
</div>
<div class="day">
<p id="day6">
<span id="minTemp6"></span>
<span id="maxTemp6"></span>
</p>
<canvas width="100" height="100" id="canvas6"></canvas>
</div>
</div>
</div>
</body>
</html>