Skip to content

Commit 713faee

Browse files
authoredOct 23, 2021
Merge pull request karangaikwad#6 from RushikeshPandekar/main
Api added
2 parents e74b084 + f44c5d5 commit 713faee

File tree

2 files changed

+60
-37
lines changed

2 files changed

+60
-37
lines changed
 

‎src/App.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ body{
5050
.Todays_weather{
5151
margin-left: 10vh;
5252
/* border:2px solid black; */
53-
width:500px;
53+
width:550px;
5454
display: flex;
5555
flex-wrap: wrap;
5656
padding:40px;
@@ -87,7 +87,7 @@ body{
8787
.temp{
8888
float:left;
8989
color: white;
90-
font-size: 60px;
90+
font-size: 40px;
9191
font-weight: 500;
9292
margin:6px;
9393
}

‎src/App.js

+58-35
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,102 @@
11
import './App.css';
22
import "axios";
3+
import { useState } from 'react';
4+
import axios from 'axios';
35

46
function App() {
7+
8+
const [weather,setWeather]=useState("");
9+
const apikey="c6b22ba82ac0661c3d775b2062b31250";
10+
11+
const apiCall=async(event)=>{
12+
event.preventDefault();
13+
const loc=event.target.elements.loc.value;
14+
const res=await axios.get(`https://api.openweathermap.org/data/2.5/weather?q=${loc}&units=metric&appid=${apikey}`);
15+
setWeather({
16+
descp: res.data.weather[0].description,
17+
temp:res.data.main.temp,
18+
city:res.data.name,
19+
icon:res.data.weather[0].icon,
20+
pressure:res.data.main.pressure,
21+
humidity:res.data.main.humidity,
22+
mintemp:res.data.main.temp_min,
23+
maxtemp:res.data.main.temp_min,
24+
windspeed:res.data.wind.speed,
25+
});
26+
};
27+
// let k=weather.temp;
28+
// let c=k.toFixed(2);
529
return (
6-
<div class = "weatherApp">
7-
8-
9-
30+
<div className = "weatherApp">
1031
<div className="Todays_weather">
11-
<div className="temp">16 &deg;</div>
32+
<div className="temp">{weather.temp} &deg;</div>
1233
<div className="city_datetime">
13-
<span className="city">London</span>
34+
<span className="city">{weather.city}</span>
1435
<span className="datetime">06:09-Monday 9 sep'19</span>
1536
</div>
1637
<div className="weather">
17-
<img src="http://openweathermap.org/img/wn/10d@2x.png" alt="weather icon" className="w-icon" height="50px" width="50px"></img>
18-
<span>Cloudy</span>
38+
<img src={`http://openweathermap.org/img/wn/${weather.icon}@2x.png`} alt="weather icon" className="w-icon" height="50px" width="50px"></img>
39+
<span>{weather.descp}</span>
1940
</div>
2041

2142
</div >
2243

23-
<div class="App">
44+
<div className="App">
2445
<div>
2546

26-
<div class="input">
27-
<form class="d-flex">
28-
<input class="form-control me-2" type="search" placeholder="Search Here" aria-label="Search" />
29-
<button class="btn" type="submit">Search</button>
47+
<div className="input">
48+
<form className="d-flex" onSubmit={apiCall}>
49+
<input className="form-control me-2" type="search" placeholder="Search Here" aria-label="Search" name="loc"/>
50+
<button className="btn" type="submit">Search</button>
3051
</form>
3152

3253

3354

3455
</div>
3556
<hr></hr>
36-
<div class="page">Todays weather</div>
57+
<div className="page">Todays weather</div>
3758
<table>
59+
<tbody>
60+
<tr>
61+
<th>Min Temp</th>
62+
<td>{weather.mintemp}&deg;</td>
63+
</tr>
3864
<tr>
39-
<th>Clouds</th>
40-
<td>50%</td>
65+
<th>Max Temp</th>
66+
<td>{weather.maxtemp}&deg;</td>
4167
</tr>
4268
<tr>
43-
<th>Density</th>
44-
<td>5.3Kg/m<sup>3</sup></td>
69+
<th>Presssure</th>
70+
<td>{weather.pressure}</td>
71+
</tr>
72+
<tr>
73+
<th>Humidity</th>
74+
<td>{weather.humidity}</td>
4575
</tr>
4676
<tr>
4777
<th>WindSpeed</th>
48-
<td>20mph</td>
78+
<td>{weather.windspeed}</td>
4979
</tr>
80+
</tbody>
5081
</table>
5182
<hr></hr>
52-
<div class="page">Cities</div>
53-
{/* <div class = "cities">
83+
<div className="page">Cities</div>
84+
{/* <div className = "cities">
5485
<button id="butn1">Button</button>
5586
<button id="butn2">Button</button>
5687
<button id="butn3">Button</button>
5788
<button id="butn4">Button</button>
5889
</div> */}
59-
<div class = "cities">
60-
<div><button class="butn">Pune</button></div>
61-
<div><button class="butn">Kolkata</button></div>
62-
<div><button class="butn">London</button></div>
63-
<div><button class="butn">Paris</button></div>
90+
<div className = "cities">
91+
<div><button className="butn">Pune</button></div>
92+
<div><button className="butn">Kolkata</button></div>
93+
<div><button className="butn">London</button></div>
94+
<div><button className="butn">Paris</button></div>
6495
</div>
6596
</div>
6697
</div>
6798
</div>
68-
69-
70-
71-
72-
73-
74-
75-
76-
);
99+
);
77100
}
78101

79102
export default App;

0 commit comments

Comments
 (0)
Please sign in to comment.