Giter Club home page Giter Club logo

weather-app's Introduction

Weather APP wanna be

Web server:

Your nodejs version should be v7 or newer.

To start the web server you have to provide environment variable for you app key:

export WEATHER_APP_KEY=you_app_key

After you have the environment variable. You can start the web server with:

npm install
node index.js

Open http://localhost:8181 in your browser

Web server Api

GET: /                           - will render the home page
GET: /get-city/{CITY_ID}         - will return the reduced data for 5 days
GET: /get-city-details/{CITY_ID} - will return full non-reduced data

WeatherAPI Class

This class will execute requests to get a city's weather data from https://openweathermap.org/forecast5

And since OpenWeatherMap allows one request per 10 minutes (or your APPKEY will be blocked for a while) the result from the first request will be kept into a file in your temp folder.

The cache file will expire on every 12 minutes (stay on the safe side regarding the 10 minutes. I don't want to take the risk :))

Usage

Initialize:

let WeatherAPI = require('./lib/weather-api')
let weatherApi = new WeatherAPI(APPKEY)

Will throw error if the APPKEY is missing.

Getting weather by cityid:

weatherApi.get(cityId)

Reduce the results function

The OpenWeatherMap JSON response contains list property. Pass it to the function and it will combine all results by date keeping only the minimal and maximal temperature for the day.

weatherApi.reduce(response.list)

Tests

Run:

npm test

No HTTP requests and no files were harmed during the unit tests execution (They are fully isolated by stubing the curlrequest and fs methods)

weather-app's People

Contributors

ibetovski avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.