-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
169 lines (95 loc) · 4.63 KB
/
Copy pathscript.js
File metadata and controls
169 lines (95 loc) · 4.63 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
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
$(document).ready(function () {
var currentDay = moment().format('LL');
$("#addDate").append(currentDay);
$("#date").append(currentDay);
$('#search-button').on("click", function (event) {
event.preventDefault();
console.log("clicked");
var searchValue = $("#search-value").val().trim();
$("#city").text(searchValue);
$("#date").show();
$(".history").on("click", "li", function () {
searchWeather($(this).val());
console.log(this);
$("#search-value").val(" ");
});
function makeRow(text) {
var li = $("<li>").addClass("list-group-item list-group-item-action").text(text);
$(".history").append(li);
}
var queryURL = "https://api.openweathermap.org/data/2.5/weather?q=" + searchValue + "&appid=4c977f45a07a9d54331ea1e40d5a5185";
function searchWeather() {
$.ajax({
type: "GET",
url: queryURL,
dataType: "json",
}).then(function (response) {
// console.log(response);
var city = $("<div>");
// $("#date").classList.remove("hide");
var cityName = (response.value);
$("#city").text(cityName);
$("#city").css({"color": "black" })
$("#temp").text("Temperature: ");
var temperatureFarenheit = ((response.main.temp - 273.15) * 1.8) + 32;
$(".temperatureFarenheit").append(Math.round(temperatureFarenheit) + " °F");
$("#humidity").text("Humidity: ");
$(".currentHumidity").append(response.main.humidity + " %");
$("#windSpeed").text("Wind Speed: ");
$(".currentWindSpeed").append(response.wind.speed + " MPH");
//UV index here
var lat = response.coord.lat;
var lon = response.coord.lon;
var uvUrl = "https://api.openweathermap.org/data/2.5/uvi?appid=4c977f45a07a9d54331ea1e40d5a5185&lat=" + lat + "&lon=" + lon;
$.ajax({
type: "GET",
url: uvUrl,
dataType: "json",
}).then(function (response) {
console.log(response, "hey Joe");
$("#uvIndex").text("UV Index: ");
$(".currentUvIndex").append(response.value);
//conditional that color codes uv index
var indexSymbol = (response.value);
console.log(indexSymbol);
if (indexSymbol >= 8.0) {
$("#uvIndex").css({ "border": "1px solid black", "background-color": "lightred" });
} else if (indexSymbol >= 5.9) {
$("#uvIndex").css({ "border": "1px solid black", "background-color": "yellow" });
} else {
$("#uvIndex").css({ "border": "1px solid black", "background-color": "lightgreen" });
}
});
//5 day forecast
var fiveDayUrl = "https://api.openweathermap.org/data/2.5/onecall?lat=" + lat + "&lon=" + lon + "&appid=4c977f45a07a9d54331ea1e40d5a5185&units=imperial"
$.ajax({
type: "GET",
url: fiveDayUrl,
dataType: "json",
}).then(function (response) {
console.log(response);
moment.unix(response.daily[0].dt).format()
console.log(moment.unix(response.daily[0].dt).format("M/D/YY"))
//allows temp data to be ordered on each card
$("#dayOneTemp").text(Math.round(response.daily[0].temp.day) + " °F");
$("#dayOneHumidity").text(response.daily[0].humidity + " % Humidity");
$("#dayOneDate").text(moment.unix(response.daily[0].dt).format("M/D/YY"));
$("#dayTwoTemp").text(Math.round(response.daily[1].temp.day) + " °F");
$("#dayTwoHumidity").text(response.daily[1].humidity + " % Humidity");
$("#dayTwoDate").text(moment.unix(response.daily[1].dt).format("M/D/YY"));
$("#dayThreeTemp").text(Math.round(response.daily[2].temp.day) + " °F");
$("#dayThreeHumidity").text(response.daily[2].humidity + " % Humidity");
$("#dayThreeDate").text(moment.unix(response.daily[2].dt).format("M/D/YY"));
$("#dayFourTemp").text(Math.round(response.daily[3].temp.day) + " °F");
$("#dayFourHumidity").text(response.daily[3].humidity + " % Humidity");
$("#dayFourDate").text(moment.unix(response.daily[3].dt).format("M/D/YY"));
$("#dayFiveTemp").text(Math.round(response.daily[4].temp.day) + " °F");
$("#dayFiveHumidity").text(response.daily[4].humidity + " % Humidity");
$("#dayFiveDate").text(moment.unix(response.daily[4].dt).format("M/D/YY"));
});
});
};
searchWeather(searchValue);
makeRow(searchValue);
});
});