-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added weather feature #21
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
let weather = { | ||
"apikey": "375090722ff9b13931a9ed44d6f32f14", | ||
|
||
// Fetch data from openweathermap API call. | ||
fetchWeather: function (city) { | ||
fetch( | ||
"http://api.openweathermap.org/data/2.5/weather?q=" | ||
+ city | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was use openweathermap forecast in several projects and i recommend use See |
||
+ "&units=metric&appid=" | ||
+ this.apikey | ||
) | ||
.then((response) => response.json()) | ||
.then((data) => this.displayWeather(data)); | ||
}, | ||
// Utilize data from the API call | ||
displayWeather: function(data) { | ||
const { name } = data; | ||
const { icon, description } = data.weather[0]; | ||
const { temp, humidity } = data.main; | ||
const { speed } = data.wind; | ||
|
||
document.querySelector(".city").innerText = "Weather in " + name; | ||
document.querySelector(".icon").src = | ||
"https://openweathermap.org/img/wn/"+ icon + ".png"; | ||
document.querySelector(".description").innerText = description; | ||
document.querySelector(".temp").innerText = temp + "°C"; | ||
document.querySelector(".humidity").innerText = "Humidity: " + humidity + "%"; | ||
document.querySelector(".wind").innerText = "Wind speed: " + speed + " km/h"; | ||
|
||
}, | ||
search: function (){ | ||
this.fetchWeather(document.querySelector(".search-bar").value); | ||
}, | ||
}; | ||
|
||
// Allow users to search with "Enter" button | ||
document.querySelector(".search button").addEventListener("click", function(){ | ||
weather.search(); | ||
}); | ||
document.querySelector(".search-bar").addEventListener("keyup", function (event) { | ||
if (event.key == "Enter") { | ||
weather.search(); | ||
} | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
<script src="https://code.iconify.design/1/1.0.7/iconify.min.js"></script> | ||
</head> | ||
|
||
<body onload="loadFunctions()"> | ||
<body onload="loadFunctions(); weather.fetchWeather('san diego')"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also you need move place for weather forecast into ENV variable |
||
|
||
<section id="modal"> | ||
<div> | ||
|
@@ -74,8 +74,37 @@ <h2>Search options</h2> | |
<section id="header"> | ||
<h2 id="header_date"></h2> | ||
<h1 id="header_greet"></h1> | ||
|
||
</section> | ||
|
||
<section id="weather"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you need use |
||
<div class="card"> | ||
<div class="search"> | ||
<input type="text" class="search-bar" placeholder="Enter your City"> | ||
<button class="weatherSearch"><svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024" height="1em" | ||
width="1.5em" xmlns="http://www.w3.org/2000/svg"> | ||
<path | ||
d="M909.6 854.5L649.9 594.8C690.2 542.7 712 479 712 412c0-80.2-31.3-155.4-87.9-212.1-56.6-56.7-132-87.9-212.1-87.9s-155.5 31.3-212.1 87.9C143.2 256.5 112 331.8 112 412c0 80.1 31.3 155.5 87.9 212.1C256.5 680.8 331.8 712 412 712c67 0 130.6-21.8 182.7-62l259.7 259.6a8.2 8.2 0 0 0 11.6 0l43.6-43.5a8.2 8.2 0 0 0 0-11.6zM570.4 570.4C528 612.7 471.8 636 412 636s-116-23.3-158.4-65.6C211.3 528 188 471.8 188 412s23.3-116.1 65.6-158.4C296 211.3 352.2 188 412 188s116.1 23.2 158.4 65.6S636 352.2 636 412s-23.3 116.1-65.6 158.4z"> | ||
</path> | ||
</svg></button> | ||
</div> | ||
<div class ="weather loading"> | ||
<h3 class="city">Weather in London</h3> | ||
<div class="temp">51°C</div> | ||
<div class="search-icon"> | ||
<img scr"" alt="" class="icon" /> | ||
</div> | ||
<div class="description">Cloudy</div> | ||
<div class="humidity">Humidity: 60%</div> | ||
<div class="wind">Wind speed: 6.2km/h</div> | ||
</div> | ||
</div> | ||
|
||
|
||
</section> | ||
|
||
|
||
|
||
<section id="apps"> | ||
<script type="text/handlebars-template" id="apps-template"> | ||
<h3>Applications</h3> | ||
|
@@ -122,6 +151,7 @@ <h4>{{category}}</h4> | |
<script src="./assets/js/script.js" type="text/javascript"></script> | ||
<script src="./assets/js/themer.js" type="text/javascript"></script> | ||
<script src="./assets/js/search.js" type="text/javascript"></script> | ||
<script src="./assets/js/weatherApp.js" type="text/javascript" defer></script> | ||
|
||
</body> | ||
</html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public apikey will be banned. you need to move it into ENV variable and enable weather feature only if apikey setted