As a tech test, I was given the following outline:
We have a small task for you using the getaddress.io API (see https://getaddress.io/). You can use the language and database of your choice.
- Write a console app that asks for a postcode.
- Check if the postcode already exists in a database and the results are less than 24 hours old.
- If it is not in the database, call the API and get addresses associated with the postcode – cache the results to a database
- Print the addresses to the screen (from the API or the pre-cached data)
- Ask for another postcode
Language: Python
Database: MongoDB
I've chosen MongoDB because:
- Mongo is built for storing JSON docs
- It has a built in Time To Live feature to delete docs after a specified time, which will be useful for expiring results after 24 hours
The console program will execute as a continuous loop, until the user exits:
- Console Input: Ask user to provide Postcode to look up, or (q)uit
- Request Postcode record from DB, if exists:
- Yes: Send record to Print_Addresses()
- No:
- Query getAddress API for current record (format & sorted = true)
- Store record in DB
- Send record to Print_Addresses()
- Print_Addresses() takes a JSON of format: {addresses:[address:[lines]]}
- for address in addresses
- for line in address.formatted_address
- print(line) if not blank
- for line in address.formatted_address
- for address in addresses
- Loop back to start
The Following EnVars will need setting:
Key | Description |
---|---|
APIKEY | Your getaddress.io API Key (https://getaddress.io/CreateAccount) |
MONGODB_URI | MongoDB Atlas connection string |
Install python dependencies with:
pip3 install -r requirements.txt