-
Notifications
You must be signed in to change notification settings - Fork 0
/
deuchainn.js
184 lines (159 loc) · 10.5 KB
/
deuchainn.js
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
window.addEventListener('load', ()=> {
let long;
let lat;
const currentSummary = document.querySelector(".current-summary");
const temp = document.querySelector(".temp");
const appTemp = document.querySelector(".app-temp");
const windSpeed = document.querySelector(".wind");
const precip = document.querySelector(".precip");
const dailyDay1 = document.querySelector('.day-1-day');
const dailyDay2 = document.querySelector('.day-2-day');
const dailyDay3 = document.querySelector('.day-3-day');
const dailyDay4 = document.querySelector('.day-4-day');
const dailyDay5 = document.querySelector('.day-5-day');
const dailyDay6 = document.querySelector('.day-6-day');
const dailyDay7 = document.querySelector('.day-7-day');
const dailyTemp1 = document.querySelector('.day-1-temp');
const dailyTemp2 = document.querySelector('.day-2-temp');
const dailyTemp3 = document.querySelector('.day-3-temp');
const dailyTemp4 = document.querySelector('.day-4-temp');
const dailyTemp5 = document.querySelector('.day-5-temp');
const dailyTemp6 = document.querySelector('.day-6-temp');
const dailyTemp7 = document.querySelector('.day-7-temp');
const dailyAppTemp1 = document.querySelector('.day-1-app-temp');
const dailyAppTemp2 = document.querySelector('.day-2-app-temp');
const dailyAppTemp3 = document.querySelector('.day-3-app-temp');
const dailyAppTemp4 = document.querySelector('.day-4-app-temp');
const dailyAppTemp5 = document.querySelector('.day-5-app-temp');
const dailyAppTemp6 = document.querySelector('.day-6-app-temp');
const dailyAppTemp7 = document.querySelector('.day-7-app-temp');
const dailyWind1 = document.querySelector('.day-1-wind');
const dailyWind2 = document.querySelector('.day-2-wind');
const dailyWind3 = document.querySelector('.day-3-wind');
const dailyWind4 = document.querySelector('.day-4-wind');
const dailyWind5 = document.querySelector('.day-5-wind');
const dailyWind6 = document.querySelector('.day-6-wind');
const dailyWind7 = document.querySelector('.day-7-wind');
const dailyPrecip1 = document.querySelector('.day-1-precip');
const dailyPrecip2 = document.querySelector('.day-2-precip');
const dailyPrecip3 = document.querySelector('.day-3-precip');
const dailyPrecip4 = document.querySelector('.day-4-precip');
const dailyPrecip5 = document.querySelector('.day-5-precip');
const dailyPrecip6 = document.querySelector('.day-6-precip');
const dailyPrecip7 = document.querySelector('.day-7-precip');
const dailySummary1 = document.querySelector('.day-1-summary');
const dailySummary2 = document.querySelector('.day-2-summary');
const dailySummary3 = document.querySelector('.day-3-summary');
const dailySummary4 = document.querySelector('.day-4-summary');
const dailySummary5 = document.querySelector('.day-5-summary');
const dailySummary6 = document.querySelector('.day-6-summary');
const dailySummary7 = document.querySelector('.day-7-summary');
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(position => {
long = position.coords.longitude;
lat = position.coords.latitude;
const proxy = 'https://api.allorigins.win/raw?url=';
const api = `${proxy}https://api.darksky.net/forecast/9e00d522da20f32ddb9cc5f341b5338a/${lat},${long}?lang=gd&units=uk2`;
fetch(api)
.then(response =>{
return response.json();
})
.then(data => {
console.log(data);
const { temperature, summary, icon } = data.currently;
const { time } = data.daily;
let unix_timestamp1 = data.daily.data[1].time
var date = new Date(unix_timestamp1 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate1 = days[date.getDay()];
console.log(formattedDate1)
let unix_timestamp2 = data.daily.data[2].time
var date = new Date(unix_timestamp2 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate2 = days[date.getDay()];
console.log(formattedDate2)
let unix_timestamp3 = data.daily.data[3].time
var date = new Date(unix_timestamp3 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate3 = days[date.getDay()];
console.log(formattedDate3)
let unix_timestamp4 = data.daily.data[4].time
var date = new Date(unix_timestamp4 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate4 = days[date.getDay()];
console.log(formattedDate4)
let unix_timestamp5 = data.daily.data[5].time
var date = new Date(unix_timestamp5 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate5 = days[date.getDay()];
console.log(formattedDate5)
let unix_timestamp6 = data.daily.data[6].time
var date = new Date(unix_timestamp6 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate6 = days[date.getDay()];
console.log(formattedDate6)
let unix_timestamp7 = data.daily.data[7].time
var date = new Date(unix_timestamp7 * 1000);
var days = ["Dìdomhnaich", "Diluain", "Dimàirt", "Diciadain", "Diardaoin", "Dihaoine", "Disaithairne"];
var formattedDate7 = days[date.getDay()];
console.log(formattedDate7)
// Set DOM Elements from the API
temp.textContent = temperature + " °C";
appTemp.textContent = data.currently.apparentTemperature + " °C";
currentSummary.textContent = summary;
windSpeed.textContent = data.currently.windSpeed + " m.s.u.";
precip.textContent = data.currently.precipIntensity + " mm.s.u.";
dailyDay1.textContent = formattedDate1;
dailyDay2.textContent = formattedDate2;
dailyDay3.textContent = formattedDate3;
dailyDay4.textContent = formattedDate4;
dailyDay5.textContent = formattedDate5;
dailyDay6.textContent = formattedDate6;
dailyDay7.textContent = formattedDate7;
dailyTemp1.textContent = data.daily.data[1].temperatureHigh + " °C";
dailyTemp2.textContent = data.daily.data[2].temperatureHigh + " °C";
dailyTemp3.textContent = data.daily.data[3].temperatureHigh + " °C";
dailyTemp4.textContent = data.daily.data[4].temperatureHigh + " °C";
dailyTemp5.textContent = data.daily.data[5].temperatureHigh + " °C";
dailyTemp6.textContent = data.daily.data[6].temperatureHigh + " °C";
dailyTemp7.textContent = data.daily.data[7].temperatureHigh + " °C";
dailyAppTemp1.textContent = data.daily.data[1].apparentTemperatureHigh + " °C";
dailyAppTemp2.textContent = data.daily.data[2].apparentTemperatureHigh + " °C";
dailyAppTemp3.textContent = data.daily.data[3].apparentTemperatureHigh + " °C";
dailyAppTemp4.textContent = data.daily.data[4].apparentTemperatureHigh + " °C";
dailyAppTemp5.textContent = data.daily.data[5].apparentTemperatureHigh + " °C";
dailyAppTemp6.textContent = data.daily.data[6].apparentTemperatureHigh + " °C";
dailyAppTemp7.textContent = data.daily.data[7].apparentTemperatureHigh + " °C";
dailyWind1.textContent = data.daily.data[1].windSpeed + " m.s.u.";
dailyWind2.textContent = data.daily.data[2].windSpeed + " m.s.u.";
dailyWind3.textContent = data.daily.data[3].windSpeed + " m.s.u.";
dailyWind4.textContent = data.daily.data[4].windSpeed + " m.s.u.";
dailyWind5.textContent = data.daily.data[5].windSpeed + " m.s.u.";
dailyWind6.textContent = data.daily.data[6].windSpeed + " m.s.u.";
dailyWind7.textContent = data.daily.data[7].windSpeed + " m.s.u.";
dailyPrecip1.textContent = data.daily.data[1].precipIntensity + " mm.s.u.";
dailyPrecip2.textContent = data.daily.data[2].precipIntensity + " mm.s.u.";
dailyPrecip3.textContent = data.daily.data[3].precipIntensity + " mm.s.u.";
dailyPrecip4.textContent = data.daily.data[4].precipIntensity + " mm.s.u.";
dailyPrecip5.textContent = data.daily.data[5].precipIntensity + " mm.s.u.";
dailyPrecip6.textContent = data.daily.data[6].precipIntensity + " mm.s.u.";
dailyPrecip7.textContent = data.daily.data[7].precipIntensity + " mm.s.u.";
dailySummary1.textContent = data.daily.data[1].summary;
dailySummary2.textContent = data.daily.data[2].summary;
dailySummary3.textContent = data.daily.data[3].summary;
dailySummary4.textContent = data.daily.data[4].summary;
dailySummary5.textContent = data.daily.data[5].summary;
dailySummary6.textContent = data.daily.data[6].summary;
dailySummary7.textContent = data.daily.data[7].summary;
// Set icon
setIcons(icon, document.querySelector(".icon"));
});
});
}
function setIcons(icon, iconID) {
const skycons = new Skycons({ color: "white" });
const currentIcon = icon.replace(/-/g, "_").toUpperCase();
skycons.play();
return skycons.set(iconID, Skycons[currentIcon]);
}
});