Weather Service
Coding Exercise
Write an http server that uses the Open Weather API that exposes an endpoint that takes in lat/long
coordinates. This endpoint should return what the weather condition is outside in that area (snow, rain,
etc), whether it’s hot, cold, or moderate outside (use your own discretion on what temperature equates to
each type).
The API can be found here:https://openweathermap.org/api. Even though most of the API calls found on
OpenWeather aren’t free, you should be able to use the free “current weather data” API call for this
project. First, sign-up for an account, which shouldn’t require credit card or payment information. Once
you’ve created an account, use https://openweathermap.org/faq to get your API Key setup to start using
the API.
Once you’ve coded your project, add it to a publicly accessible Github repository and share it
with the team. Additionally, please don’t add your API Key to the project. Each member of the
team reviewing your code has their own key to use for testing your project.
- Latitude
- Longitude
- Conditions: (ENUM)
- Raining
- Sunny
- Snowing
- Cloudy
- Temperature
- Cold (T <= 32 degrees F)
- Moderate (32< T <90 degrees F)
- Hot (>=90 Degrees F)
- Latitude Invalid - return 400
- Longitude Invalid - return 400
- Lat/Long Valid, Weather Service API up, API key valid - return 200
- Lat/Long Valid, Weather Service API down - return 503
- Lat/Long Valid, Weather Service APIup, API key invalid - return 403
- Set up a Python Flask Server
- Add a GET API route with
lat
& `long GET parameters - Validate lat & long GET parameters`- return 400 if invalid
- Make Weather API Request
- Handle Weather Response 500 - return 500
- Handle Weather Response 401 - return 401
- Handle 200 - parse data from response return formatted JSON
{
'coord': {'lon': 90, 'lat': 90},
'weather': [
{
'id': 803,
'main': 'Clouds',
'description': 'broken clouds',
'icon': '04n'
}
],
'base': 'stations',
'main':
{
'temp': 258.67,
'feels_like': 253.25,
'temp_min': 258.67,
'temp_max': 258.67,
'pressure': 1036,
'humidity': 97,
'sea_level': 1036,
'grnd_level': 1036
},
'visibility': 10000,
'wind':
{
'speed': 2.33,
'deg': 300,
'gust': 2.23
},
'clouds': {'all': 52},
'dt': 1714604721,
'sys': {'sunrise': 0, 'sunset': 0},
'timezone': 21600,
'id': 0,
'name': '',
'cod': 200}
NOTE: We will be using the get param units=standard to ensure temperature units are in kelvin
Data relevant to the project:
Conditions - ['weather'][0]['description'] - Using this for conditions
Temperature - ['main']['feels_like'] - Use this for feeling of temperature, convert to Fahrenheit and map to feeling based on range; (Cold, Moderate, Hot)