We have some customer records in a text file (customers.txt) -- one customer per line, JSON lines formatted. We want to invite any customer within 100km of our Dublin office for some food and drinks on us. Write a program that will read the full list of customers and output the names and user ids of matching customers (within 100km), sorted by User ID (ascending).
The project is written in python 3. Please follow the below instructions to install Python on your machine.
Download the project using
git clone https://github.com/uddish/intercom.gitInstall pip 🔗
python3 -m pip install --user --upgrade pip
You can check installed pip's version using:
python3 -m pip --version
The Python installers for Windows include pip. You should be able to access pip using:
py -m pip --version
pip 9.0.1 from c:\python36\lib\site-packages (Python 3.6.1)
You can make sure that pip is up-to-date by running:
py -m pip install --upgrade pip
Install Virtualenv 🔗
python3 -m pip install --user virtualenv
py -m pip install --user virtualenv
Creating and activating a Virtual environment 🔗
Go the the downloaded intercom folder by using
cd intercom
Create a virtual environment using the below command
python3 -m venv env
Activate a virtual environment using the below command
source env/bin/activate
Create a virtual environment using the below command
py -m venv env
Activate a virtual environment using the below command
.\env\Scripts\activate
To leave the Virtual environment, simply use
deactivate
Pssst... Do you use a Mac? 👩💻
Option 1
- Use Homebrew to install python ->
brew install python - Don't have homebrew installed? Go to the Install Homebrew section
Option 2
- You can also use the official python installer. Check this.
Option 3
- Still not sure how to install Python. Follow this extensive guide
Are you a windows user? 🖥
Option 1
- Use the official Python installer.
Option 2
- Still stuck? Follow this extensive guide
Linux and Other Platforms? 💻
- Install python on Linux by following this guide
- Install python on other platforms. Check this link
python --version- The project contains a main.py file that acts as the entry point to the program.
- There is a sample customers.txt file that is used to read the customer data.
- The output generated is stored in a separate output.txt file.
- The Project contains a services folder.
- All the logic related to reading/writing to the files can be found inside input_output_service.py
- All the logic related to calculating the distance between the customer and the Intercom office can be found inside customer_invitation_service.py
- There is a separate tests folder that contains the code related to running the Unit Tests.
- test.py contains all the unit tests logic.
- Unit tests have their own input/output files which can also be found inside the tests folder.
Make sure that you are in the root /intercom folder.
Also, make sure that you virtual environment has been created and activated.
You can use the Creating and activating a Virtual environment section mentioned above to create and activate a virtualenv.
Try running the below command(after activating the virtualenv) to run the Test Cases
python -m unittest tests/test.pyHere, tests is the directory where all the test cases and the corresponding input/output files are present.
test.py is the actual file that is being executed.
The project has a sample customers.txt file which will be used to read the customer data.
Make sure that you are in the root /intercom folder.
Run the below command to execute the program.
python main.pyStay with me, let's look at the output 😃
Check the output.txt file to look for the desired output.
Please feel free to reach out to me here: Uddish Verma