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
sure_weather
repository
In a seperate directory, clone the 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
-
The API endpoint is http://localhost:8080/current_weather
-
Only support
GET
method
Table 1. Request Parameters: Request Parameters
Key | Value | Description |
---|---|---|
|
floating-point number between |
Required if using along with |
|
floating-point number between |
Required if using along with |
|
a positive 5-6 digit number, Example: |
Optional, use either |
|
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'
{
"latitude": 30.4570672,
"longitude": -97.68194299999999,
"datetime": "2019-10-20T22:15:12",
"services": [
"weather.com",
"accuweather",
"noaa"
],
"temperature": {
"fahrenheit": 49,
"celsius": 9.44
}
}
Table 2. Request JSON Attributes: Response JSON
Key | Value |
---|---|
|
Floating-point number between |
|
Floating-point number between |
|
Timestamp in UTC ISO-8601 format |
|
List of services used in getting the current weather data |
|
Current temperature in |
|
Current temperature in |
Example 2
curl -X GET --insecure --globoff 'http://localhost:8080/current_weather?zipcode=78728'