Pre-requisites:
- Python 3.10+
- pip 22.3+
Run the following commands to clone the project, create a virtual environment and install the project dependencies:
git clone https://github.com/linomp/distance-tool-with-automation.git
cd distance-tool-with-automation
# Windows
python -m venv venv
call venv\Scripts\activate.bat
# MacOS/Linux
python3 -m venv venv
source ./venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
playwright install chromium
-
Create an input
.txt
file containing two addresses per line (origin and destination), separated by a delimiter (e.g. comma, tab, semicolon).Here is an example of tab-delimited input file (
<TAB>
added for readability, normally they are not visible in the file):Via Livorno 60, Torino (TO)<TAB>Corso Umberto I, 29, 28838 Stresa VB Environment Park Torino<TAB>Hotel Regina Palace Stresa Via Livorno 60, Torino (TO)<TAB>Via Lincoln, 2, 90133 Palermo PA Environment Park Torino<TAB>Orto botanico Palermo Torino<TAB>Palermo
Note: from Excel you can export an .xlsx as a tab-delimited .txt file
-
Launch the app:
# Windows/MacOS/Linux streamlit run app_ui.py
Then visit http://localhost:8501/ to use the browser-based UI:
Or invoke the app from command-line (advanced)
# Windows/MacOS/Linux python app.py -i data/input.txt -d "\t" # MacOS/Linux python3 app.py -i data/input.txt -d "\t"
-
The tool will process the input file line-by-line, calculating the distance between every pair of addresses and writing the result in a
.csv
output file. The final result will look like this:
The app has an optional notification feature (via telegram bot).
Steps to enable it
- Search for
@BotFather
in Telegram and follow the instructions to create a new bot. - Send a message to your bot and get your chat id by visiting this URL:
https://api.telegram.org/bot<your bot token>/getUpdates
- Create an .env file in the root directory of the project and add the following variables:
TELEGRAM_TOKEN=<your bot token from step 1> TELEGRAM_CHAT_ID=<your chat id from step 2>
- Check that it works. Run
pytest .
and you should see a message in the bot chat saying this :Finished processing: test_input.txt
Learn more here