Kay0s / Server-Side-APIs-Weather-Dashboard

A weather dashboard using JQuery and information from Current Weather Data and One Call APIs to provide the current weather and 5-Day forecast for a searched city.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weather Dashboard Using OpenWeather and Moment.js APIs

Overview

The client expressed needs for an application that provides weather outlook for multiple cities, so they can plan their trips.

Client's Needs/Expectations

The client, a traveler who will be visiting multiple cities, established that the following needs/expecations must be met:

  • The weather outlook application must allow the traveler to search for the weather outlook for mulitple cities, by their name.
  • The app will run in the browswer and feature dynamically updated HTML and CSS powered by JQeury.
  • Moment.js library is to be used to work with date and time and OpenWeather API to retrieve weather data for cities.

Updates and Exepctations Obtained from the Traveler, Traveling to Multiple Cities

Through information and feedback provided by the traveler who is traveling to multiple cities, the following criteria were established:

  • The traveler is using the weather dashboard to find the outlook for multiple cities, so that they can plan their trip accordingly.
  • When the traveler opens the app :
    • There are from inputs to search for a city.
      • When the traveler searches for a city:
      • They are presented with current and future conditions and that city is added to the search history.
        • When they view current weather conditions for that city
        • Then they are presented with the city name, the date, and icon representation of weather conditions, the temperature, the humidity, the wind speed and the UV index.
        • When the the traveler views the UV index
        • Then the they are presented with a color that indicates whether the conditions are favorable, moderate or severe.
  • When the traveler views future weather conditions for that city .
  • Then they are presented a 5-day forecast that displays the date, an icon representation of weather conditions, the temperature, and the humidity
  • When the traveler clicks on a city in the search history
  • Then they are again presented with current and future conditions for that city
  • When the traveler open the weather dashboard
  • Then they are presented with the last searched city forecast

Overall Deployment of Weather Dashboard

  • The $(document).ready(function) is employed so the the JQuery events and AJAX calls won't fire until their designated times.

  • On load of page: a search input and search button are present to enter a city name in order to obtain its weather forecast.

  • Also on load of page, if the (lastSearched === null), then the cityArray open array will begin.

  • When the traveler inputs the city name into the text box and clicks the search button, event listeners and functions are triggered for:

    • The city name inputed into the text box or clicked saved city to be saved to local storage and be rendered with a for loop on the page as text inside a clickable button.
    • A first AJAX call is made to Current Weather Data API to obtain the latitude and longitude of the city.
    • The last AJAX call is made to One Call API using the latitude and longitude from the first call to obtain the current weather conditions and the extended forecast in imperial, and UV index.
    • JQuery is used to render in a card and append divs to contain the current day's weather.
    • The dt from the AJAX call is passed through moment.unix().format(M/DD/YYY) to format the date.
    • The weatherIcon variable is created from the second AJAX call for the weather information (uvExtendedData.current.weather[0].icon).
    • The iconURL variable is created from OpenWeather's URL for icon images ("https://openweathermap.org/img/wn/") + the weather icon data from the AJAX call ("weatherICON) + ".png" for the image format.
    • The current temperature is obtained from (uvExtendedData.current.temp).
    • The current humidity is obtained from (uvExtendedData.current.humidity).
    • The current wind speed is obtained from (uvExtendedData.current.wind_speed).
    • The current UV index is obtained from (uvExtendedData.current.uvi) and a function with if statements adds CSS colors based on if the UV index conditions are favorable, moderate, extreme or undefined.
  • JQuery is used to render in five cards and append divs inside each to contain the 5-day forecast.

  • .map and and an if statement is used to display the searched city's 5-day forecast consisting of: the date, weather icon, temperature and humidty.

  • (day.dt) from the AJAX call is passed through moment.unix().format(M/DD/YYYY) to format the dates.

  • (day.weather[0].icon is obtained to show the weather icons.

  • The 5-day forecast temperatures are otbained from (day.temp.day).

  • The 5-day forecast humidities are otbained from (day.humidity).

  • When the traveler refreshes the application, the saved city(cities) persist as clickable button(s) and the last searched city's current weather information is presented, due to the retrieval of data from local storage and subtracting one from the retrieved array.

    • Since the traveler's searched city(cities) will be generated from an input, JSON.parse and JSON.strigify are used to set and retrieve the searched city(cities) from the client side local storage.

Tools Used

  • HTML
  • CSS
  • JQuery
  • OpenWeather - Current Weather Data API
  • OpenWeather - Once Call API
  • Moment.js

Deployed Website and JQuery Code with AJAX calls

*Deployed website *GitHub Repository Screenshot of deployed website Screenshot of finalized JavaScript Code

Research Resources

License

© 2020 Kristina Hamilton and Trilogy Education Services, a 2U, Inc. brand. All Rights Reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A weather dashboard using JQuery and information from Current Weather Data and One Call APIs to provide the current weather and 5-Day forecast for a searched city.


Languages

Language:JavaScript 68.7%Language:CSS 19.7%Language:HTML 11.6%