-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #390 from SanskarSinghiit/master
Adds Temperature API
- Loading branch information
Showing
5 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Temperature App | ||
This an API Project with JavaScript DOM. User will get the temperature by searching their city. It shows the real time data of current weather. | ||
|
||
|
||
## Technologies that are used to build this project: | ||
- HTML | ||
- CSS | ||
- Bootstrap | ||
- JS | ||
- API | ||
|
||
|
||
`Live Link`: https://temperature-api-indol.vercel.app/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<title>Temperature App</title> | ||
<!-- Required meta tags --> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<link rel="shortcut icon" href="https://cdn-icons-png.flaticon.com/512/603/603463.png" type="image/x-icon"> | ||
|
||
|
||
<!-- Bootstrap CSS --> | ||
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"> | ||
<style> | ||
body { | ||
background: url(images/2.jpg) no-repeat; | ||
background-size: cover; | ||
height: 100vh; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<form class="col-md-6 m-auto py-5"> | ||
<div class="input-group mb-3"> | ||
<input id="input-field" type="text" class="form-control" placeholder="Enter a location for Weather ..."> | ||
<div class="input-group-append"> | ||
<button onclick="searchTemperature()" type="button" class="btn btn-danger">Search</button> | ||
</div> | ||
</div> | ||
</form> | ||
<div class="weather-status text-white text-center"> | ||
<img id="weather-icon" src="https://openweathermap.org/img/wn/02d@2x.png" alt=""> | ||
<h1 id="city">Dhaka</h1> | ||
<h3><span id="temp">38.06</span>°C</h3> | ||
<h1 id="weather" class="lead">Clouds</h1> | ||
</div> | ||
</div> | ||
|
||
<script src="js/app.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const API_KEY = '233ee7523c96a40605e5ad29972a5e45'; | ||
|
||
const searchTemperature = () => { | ||
const city = document.getElementById('input-field').value; | ||
const url = `https://api.openweathermap.org/data/2.5/weather?q=${city}&appid=${API_KEY}&units=metric`; | ||
//&units=matrics dile temperature ta degree ta pabo | ||
console.log(url); | ||
fetch(url) | ||
.then(res => res.json()) | ||
.then(data => displayTemperature(data)) | ||
} | ||
|
||
const setInnerText = (id, text) => { | ||
document.getElementById(id).innerText = text; | ||
} | ||
const displayTemperature = city => { | ||
console.log(city); | ||
setInnerText('city', city.name); | ||
setInnerText('temp', city.main.temp); | ||
setInnerText('weather', city.weather[0].main); | ||
// setInnerText('weather',city.) | ||
//set weather icon | ||
const url = `https://openweathermap.org/img/wn/${city.weather[0].icon}@2x.png`; | ||
const imgIcon = document.getElementById('weather-icon'); | ||
imgIcon.setAttribute('src', url); | ||
} |