-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathweather.html
212 lines (197 loc) · 8.41 KB
/
weather.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
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Just Weather and Date</title>
<link rel='stylesheet' href='semantic.min.css'/>
<link rel='stylesheet' href='custom.css'/>
<script src='jquery-3.1.0.min.js'></script>
<script src='semantic.min.js'></script>
<script src='weather.min.js'></script>
<style>
body {
background-color: black;
}
.vertical-horizontal-center {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
-ms-transform: translateY(-50%) translateX(-50%);
transform: translateY(-50%) translateX(-50%);
}
#now_date_div {
font-size: 15rem !important;
}
#now_time_div {
font-size: 10rem !important;
}
#now_date_label {
font-size: 4rem !important;
}
#now_temp_div {
font-size: 5rem !important;
}
#now_weather_div {
font-size: 3rem !important;
}
#now_feels_like_div {
font-size: 2rem !important;
}
#now_temp_max_div {
font-size: 2rem !important;
}
#now_temp_min_div {
font-size: 2rem !important;
}
#now_humidity_div {
font-size: 2rem !important;
}
#weather_icon {
display: inline;
}
.darkgrey {
color: #333333 !important;
}
</style>
</head>
<body>
<div>
<div class='vertical-horizontal-center'>
<div class='ui huge grey inverted statistic'>
<div class='value' id='now_date_div'>
</div>
<div class='label' id='now_date_label'>
</div>
</div>
<br/>
<div class='ui huge grey inverted statistic'>
<div class='value' id='now_time_div'>
</div>
</div>
<br/>
<div class='ui fluid black inverted segment'>
<img class="ui tiny image" id='weather_icon' src="">
<div class='ui grey inverted statistic'>
<div class='value' id='now_temp_div'>
</div>
<div class='label' id='now_weather_div'>
</div>
</div>
<div class='ui grey inverted statistic'>
<div class='value' id='now_feels_like_div'>
</div>
<div class='label'>체감온도
</div>
</div>
<div class='ui grey inverted statistic'>
<div class='value' id='now_temp_max_div'>
</div>
<div class='label'>최고기온
</div>
</div>
<div class='ui grey inverted statistic'>
<div class='value' id='now_temp_min_div'>
</div>
<div class='label'>최저기온
</div>
</div>
<div class='ui grey inverted statistic'>
<div class='value' id='now_humidity_div'>
</div>
<div class='label'>습도
</div>
</div>
</div>
</div>
</div>
<script>
let start_date;
let now_date;
let weather_api_key = '1f7125d6573be3bdb8714a6097fee94f';
let weather_city_id = '1832427'; // yong in
function init() {
start_date = new Date();
drawWeather();
let hours = start_date.getHours();
if (hours >= 18 || hours < 6) {
document.querySelectorAll('div').forEach(c => c.style.color = '#999999');
}
else {
document.querySelectorAll('div').forEach(c => c.style.color = '#DCDDDE');
}
loop();
}
function drawWeather() {
Weather.setApiKey(weather_api_key);
Weather.getCurrentByCityId(weather_city_id, function(current) {
console.log(current);
const weather_icon = document.getElementById('weather_icon');
weather_icon.setAttribute('src', `http://openweathermap.org/img/w/${current.data.weather[0].icon}.png`);
let temp = Math.floor((current.data.main.temp - 273.15) * 10) / 10;
let temp_max = Math.floor((current.data.main.temp_max - 273.15) * 10) / 10;
let temp_min = Math.floor((current.data.main.temp_min - 273.15) * 10) / 10;
let feels_like = Math.floor((current.data.main.feels_like - 273.15) * 10) / 10;
let humidity = current.data.main.humidity;
const now_temp_div = document.getElementById('now_temp_div');
now_temp_div.innerText = `${temp}°C`;
const now_feels_like_div = document.getElementById('now_feels_like_div');
now_feels_like_div.innerText = `${feels_like}°C`;
const now_temp_max_div = document.getElementById('now_temp_max_div');
now_temp_max_div.innerText = `${temp_max}°C`;
const now_temp_min_div = document.getElementById('now_temp_min_div');
now_temp_min_div.innerText = `${temp_min}°C`;
const now_humidity_div = document.getElementById('now_humidity_div');
now_humidity_div.innerText = `${humidity}%`;
const now_weather_div = document.getElementById('now_weather_div');
now_weather_div.innerText = `${current.data.weather[0].main}`;
});
}
function drawDate() {
const now_date_div = document.getElementById('now_date_div');
now_date_div.innerText = `${now_date.getMonth() + 1} / ${now_date.getDate()}`;
const now_date_label = document.getElementById('now_date_label');
now_date_label.innerText = `${now_date.toLocaleString('en-us', {weekday:'long'})}`
const now_time_div = document.getElementById('now_time_div');
now_time_div.innerText = `${now_date.toString().split(' ')[4]}`;
}
function loop() {
now_date = new Date();
drawDate();
// 15 minutes later
if (now_date - start_date > 15 * 60 * 1000) {
start_date = now_date;
drawWeather();
let hours = now_date.getHours();
if (hours >= 18 || hours < 6) {
document.querySelectorAll('div').forEach(c => c.style.color = '#999999');
}
else {
document.querySelectorAll('div').forEach(c => c.style.color = '#DCDDDE');
}
}
window.requestAnimationFrame(loop);
}
window.onload = init;
function hasClass(el, className) {
if (el.classList)
return el.classList.contains(className)
else
return !!el.className.match(new RegExp('(\\s|^)' + className + '(\\s|$)'))
}
function addClass(el, className) {
if (el.classList)
el.classList.add(className)
else if (!hasClass(el, className)) el.className += " " + className
}
function removeClass(el, className) {
if (el.classList)
el.classList.remove(className)
else if (hasClass(el, className)) {
var reg = new RegExp('(\\s|^)' + className + '(\\s|$)')
el.className=el.className.replace(reg, ' ')
}
}
</script>
</body>
</html>