-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
198 lines (123 loc) · 6.05 KB
/
script.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
document.getElementById("userInput").value = "Kanpur";
function getValue() {
var city = document.getElementById("userInput").value;
console.log(city);
let url=`https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=d2f9b3beb4aa181edd0ecf94473c782f`;
const shuivam = async()=>{
const data = await fetch(url);
const isdi = await data.json();
const fa = isdi.main.temp;
const df= isdi.weather[0].main;
const rg = isdi.sys.country;
var city = isdi.name;
document.getElementById("gh").innerHTML=city;
document.getElementById("span").innerHTML=","+rg;
// icon changing
var iconcode = isdi.weather[0].icon;
var img = document.getElementById("imgf");
document.getElementById("ws").innerHTML="Weather Forecast For "+city;
// Summary section
document.getElementById("main_temp").innerHTML=Math.floor(isdi.main.temp-273)+"°C";
document.getElementById("feelslike").innerHTML=Math.floor(isdi.main.feels_like-273)+"°C";
document.getElementById("pressure").innerHTML=Math.floor(isdi.main.pressure)+"hPa";
document.getElementById("humidity").innerHTML=Math.floor(isdi.main.humidity)+"%";
document.getElementById("visibility").innerHTML=Math.floor((isdi.visibility)/1000)+"KM";
if(iconcode == "01d"){
//clear sky
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/clear-day.svg");
}else if(iconcode == "02d"){
//fewClouds
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/partly-cloudy-day.svg");
}else if(iconcode == "03d"){
//scattered clouds
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/overcast-day.svg");
}else if(iconcode == "04d"){
// broken clouds
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/cloudy.svg");
}else if(iconcode == "09d"){
// shower RAin
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/partly-cloudy-day-rain.svg");
}else if(iconcode == "11d"){
// thunderstorm
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/thunderstorms-day-rain.svg");
}else if(iconcode == "13d"){
// Snow
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/snow.svg");
}else if(iconcode == "50d"){
// mist
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/mist.svg");
}else if(iconcode == "10d"){
// rain
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/rain.svg");
}
//night Icon
else if(iconcode == "01n"){
//clear sky
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/clear-night.svg");
}else if(iconcode == "02n"){
//fewClouds
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/partly-cloudy-night.svg");
}else if(iconcode == "03n"){
//scattered clouds
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/overcast-night.svg");
}else if(iconcode == "04n"){
// broken clouds
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/overcast.svg");
}else if(iconcode == "09n"){
// shower RAin
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/partly-cloudy-night-drizzle.svg");
}else if(iconcode == "11n"){
// thunderstorm
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/thunderstorms-night-rain.svg");
}else if(iconcode == "13n"){
// Snow
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/snow.svg");
}else if(iconcode == "50n"){
// mist
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/mist.svg");
}else if(iconcode == "10n"){
// rain
img.setAttribute("src","https://basmilius.github.io/weather-icons/production/fill/all/rain.svg");
}
// console.log(img.src);
const sunrise = new Date((isdi.sys.sunrise ) * 1000).toLocaleTimeString();
const sunset = new Date((isdi.sys.sunset ) * 1000).toLocaleTimeString();
var v = Math.floor(fa-273);
console.log(v);
console.log(df);
document.getElementById("th").innerHTML=Math.floor(isdi.main.temp_max-273)+"°C";
document.getElementById("tm").innerHTML=Math.floor(isdi.main.temp_min-273)+"°C";
document.getElementById("hawa").innerHTML=Math.floor((isdi.wind.speed*3.6))+"Kmph";
document.getElementById("rise").innerHTML=sunrise;
document.getElementById("set").innerHTML=sunset;
console.log(sunrise);
console.log(sunset);
document.getElementById("cts").innerHTML=df;
var c = document.getElementById("shi");
c.innerHTML=v+"°C";
}
shuivam();
}
shuivam();
function getQuote(){
let url=`https://api.quotable.io/quotes/random`;
const quote = document.getElementById("qutoe");
const cite = document.getElementById("author");
const ishu = async()=>{
const data2 = await fetch(url);
const data3 = await data2.json();
quote.innerHTML = data3[0].content;
cite.innerHTML = "       "+data3[0].author;
console.log(data3[0].author)
}
ishu();
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var d = new Date();
var f = months[d.getMonth()];
var din = days[d.getDay()];
var tarikh = d.getDate();
var dinak = [din,tarikh+"th",f]
// console.log(dinak);
let fullDate = document.getElementById("dateFull").innerHTML=din+" "+tarikh+"th"+" "+f;
}