Giter VIP home page Giter VIP logo

sure_weather's Introduction

Sure Weather

A REST API to get current temperature for a given a location specified as (latitude and longitude) pair or a zipcode. The API relies upon externel weather services such as NOAA, Weather.com and Accuweather. aiohttp is used to build this application.

Setup

Follow these steps to setup the application

Clone and start mock-weather-api Helper Application that emulates NOAA, Weather.com and Accuweather.

git clone https://github.com/shipwell/mock-weather-api.git && \
  cd mock-weather-api && \
  python3 -m venv venv && \
  source venv/bin/activate && \
  pip3 install -r requirements.txt && \
  FLASK_APP=app.py FLASK_DEBUG=1 flask run

In a seperate directory, clone the sure_weather repository

git clone https://github.com/vamshikr/sure_weather.git && \
cd sure_weather

Create a virtual environment

python3 -m venv venv && source venv/bin/activate

Install dependencies

pip3 install -r requirements.txt

Export environment variables

export FLASK_APP="http://localhost:5000"
export WEATHERDOTCOM_URL="$FLASK_APP"
export ACCUWEATHER_URL="$FLASK_APP"
export NOAA_URL="$FLASK_APP"

If using Google Maps to verify location and get latitude and longitude from a zipcode

export GOOGLE_MAPS_APIKEY=<your google maps api key>

Start the sure_weather application

./run_server.sh
Output
20-10-2019:16:32:55,679 INFO     [__init__.py:12] Adding weather.com
20-10-2019:16:32:55,679 INFO     [__init__.py:15] weather.com added
20-10-2019:16:32:55,679 INFO     [__init__.py:12] Adding accuweather
20-10-2019:16:32:55,679 INFO     [__init__.py:15] accuweather added
20-10-2019:16:32:55,679 INFO     [__init__.py:12] Adding noaa
20-10-2019:16:32:55,679 INFO     [__init__.py:15] noaa added
======== Running on http://127.0.0.1:8080 ========

In another terminal session, run functional tests

./run_tests.sh

If all the above steps pass, then the sure_weather application is ready to use.

Using the API

API Endpoint

Request Parameters

Table 1. Request Parameters:
Key Value Description

latitude

floating-point number between -90 and +90

Required if using along with longitude

longitude

floating-point number between -180 and +180

Required if using along with latitude

zipcode

a positive 5-6 digit number, Example: 78728

Optional, use either zipcode or (latitude, longitude) pair

services

comma separated string of service names, example: `services=accuweather,noaa'

Optional, if not specified uses all the services

Example 1
curl -X GET --insecure --globoff 'http://localhost:8080/current_weather?latitude=33.33&longitude=44.44&services=accuweather,noaa'
Response
{
  "latitude": 30.4570672,
  "longitude": -97.68194299999999,
  "datetime": "2019-10-20T22:15:12",
  "services": [
    "weather.com",
    "accuweather",
    "noaa"
  ],
  "temperature": {
    "fahrenheit": 49,
    "celsius": 9.44
  }
}

Response JSON

Table 2. Request JSON Attributes:
Key Value

latitude

Floating-point number between -90 and +90

longitude

Floating-point number between -180 and +180

datetime

Timestamp in UTC ISO-8601 format

services

List of services used in getting the current weather data

temperature.fahrenheit

Current temperature in fahrenheit

temperature.celsius

Current temperature in celsius

Example 2
curl -X GET --insecure --globoff 'http://localhost:8080/current_weather?zipcode=78728'

sure_weather's People

Contributors

vamshikr 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.