forked from Return-Ready-PT-Tues-Thurs/Weather-App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
60 lines (44 loc) · 2.09 KB
/
weather.js
File metadata and controls
60 lines (44 loc) · 2.09 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
const url = 'http://api.zippopotam.us/us/90210';
let longitude = 0.0;
let latitude = 0.0;
var zippopotamApi = new XMLHttpRequest();
zippopotamApi.onreadystatechange = () => {
if(zippopotamApi.readyState == 4 ){
const locationData = JSON.parse(zippopotamApi.responseText);
const city = locationData.places[0]['place name'];
const state = locationData.places[0]['state abbreviation'];
const postCode = locationData['post code'];
longitude = parseFloat(locationData.places[0].longitude);
latitude = parseFloat(locationData.places[0].latitude);
document.getElementById('paragraph1').innerHTML = `${city}, ${state}`;
console.dir(locationData);
console.dir(longitude);
console.dir(latitude);
seventimerApi.open('GET',`http://www.7timer.info/bin/api.pl?lon=${longitude}&lat=${latitude}&product=civillight&output=json` );
seventimerApi.send();
}
};
zippopotamApi.open('GET', url);
zippopotamApi.send();
var seventimerApi = new XMLHttpRequest();
seventimerApi.onreadystatechange = () => {
if(seventimerApi.readyState == 4 ){
const seventimer = JSON.parse(seventimerApi.responseText);
const dataseries = seventimer.dataseries[0]['temp2m'];
const dataseriesMin = dataseries.min;
const dataseriesMax = dataseries.max;
const dataseriesWeather = seventimer.dataseries[0]['weather'];
const FahMin = parseFloat(dataseries.min * 9 / 5 + 32).toFixed(0);
const FahMax = parseFloat(dataseries.max * 9 / 5 + 32).toFixed(0);
console.dir(seventimer);
console.dir(dataseries);
console.dir(FahMin);
console.dir(FahMax);
console.dir(dataseries.max);
console.dir(dataseries.min);
console.dir(dataseriesWeather);
document.getElementById('paragraph2').innerHTML = `${dataseriesWeather} ${FahMin}°F`;
let image = document.getElementById('image');
image.src = 'http://www.7timer.info/bin/civillight.php?lon=-118.407&lat=34.09&lang=en&ac=0&unit=metric&tzshift=0';
}
};