Skip to content

Instantly share code, notes, and snippets.

@Voyz
Last active December 7, 2020 08:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Voyz/9939087b13dbada5dd1fd5cbecd9b67f to your computer and use it in GitHub Desktop.
Save Voyz/9939087b13dbada5dd1fd5cbecd9b67f to your computer and use it in GitHub Desktop.
Weather finder basic
*** Originally built for my mate Sam as part of our mentoring sessions. See: https://youtu.be/TXoDvTJuEb0 ***
####################
WEATHER FINDER BASIC
####################
Utilise an online weather API to fetch and display current weather information based on the city and country code provided.
###################
Specification:
1. User types in the city and country code into a search bar, separated by a comma. Hits enter or presses a 'Search' button to confirm.
2. The app fetches weather information for that city.
3.1 If the request returns an error, print out an error message
3.2 If the request fails because the city is incorrect, inform the user of misspelling.
3.3 If the request correctly returns data, display:
- City name and country code
- Current temperature in Celcius
- Current cloudiness in %
- Sunrise and sunset hours today
- One additional information that you choose - can be anything from the response.
4. The background of the page should be:
- A sunny background if cloudiness is below 50% and temperature above 20*C.
- A non-sunny background if cloudiness is below 50% and temperature below 20*C.
- A union jack if cloudiness is above 50% and temperature below 20*C.
Everything else is up to you - just make the most reasonable call on choices that may arise.
I've purposely left out one bit of the specification. I want you to handle whatever cases I haven't
described in whatever way you find reasonable to deliver the behaviour I'd most likely expect from such an app.
###################
Use the Open Weather Map's API:
https://openweathermap.org/
You will need to:
1. Sign up for their service - it is free for small use cases.
2. Read their API documentation on the Current Weather Data API. Their docs are quite good, most answers should be there.
3. Understand the correct format for city+country code URL query
4. Understand the correct format to provide the API key
###################
A bit of advice:
1. There are a few things you will need to figure out as you go through this assignment. I've tried to analyse these and
I think that if you Google right things you'll find the right answers. For instance: Some cities have a space in their name.
URL's cannot contain spaces. How do you provide a space in an URL?
2. Some weather information may be missing, therefore the data returned from the API may be incomplete. The app should be
prepared for it and display some generic 'no data found' message in place of fields that couldn't be provided.
3. Even thought it may not seem like it at a glance, it is VERY similar to the recipes app we've been looking at.
If you feel that things are too complicated, just step back and look at the recipe app to see how you can make things similarly.
###################
(Optionally)
If you feel up for a challenge, try to tackle these once you're finished:
1. Display city suggestions as user types in the search box
2. When displaying the weather data, expand the country code to full country name
3. Upon misspelling, try to suggest a correction.
4. Create a number of 'test' pages, which are pre-set to fetch particular city's weather upon opening - or 'simulate'
that the particular data already has been returned. This way you can create a test page for each case described in
the specification (temperature + cloudiness variants, misspelling in city, other errors), and use it to repeatedly
verify that your implementation handles all cases correctly.
###################
Misc:
Useful tools to test online API's:
https://reqbin.com/ (online, pretty light and simple)
https://www.postman.com/ (offline, widely used)
If you get stuck give me a shout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment