From 2114557a2b94822c543143ede657fe49a59d5297 Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Thu, 20 Jun 2024 10:17:37 +0100 Subject: [PATCH 1/7] chore: updated README --- .gitignore | 9 +++++++++ README.md | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0fb7849..75ead29 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,15 @@ ipython_config.py # pyenv .python-version +# misc +.DS_Store +*.pem +*.crt +*.db +*.db-journal +*.log +*.log.* + # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. # However, in case of collaboration, if having platform-specific dependencies or dependencies diff --git a/README.md b/README.md index f08e094..3bc2942 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ To make this project only you need to follow this step:- ## Installation -Install package with pip +### Install package with pip (Windows) ```bash pip install phonenumbers @@ -24,6 +24,14 @@ Install package with pip pip install geocoder pip install opencage ``` +### Install package with pip (Mac) +``` +python3 -m pip install phonenumbers +python3 -m pip install folium +python3 -m pip install geocoder +python3 -m pip install opencage + +``` Now need to collect Geocoder API Key from https://opencagedata.com/ From 2438f2b2c5e696dd09dc96727d11a970956ee1ab Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Thu, 20 Jun 2024 10:25:45 +0100 Subject: [PATCH 2/7] updated code to function better --- location.html | 39 ++++++++++++++------------ main.py | 78 ++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 77 insertions(+), 40 deletions(-) diff --git a/location.html b/location.html index 3dafd30..e5dd7ec 100644 --- a/location.html +++ b/location.html @@ -12,12 +12,12 @@ - + - + @@ -25,7 +25,7 @@ - - - - - - - - - - - - - - - - - - - -
- - - - \ No newline at end of file From 91643d90b0d19e4d86cf9a237ee3bf7b05bbca2a Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Thu, 20 Jun 2024 10:43:55 +0100 Subject: [PATCH 4/7] updated to use .env file. Updated README --- README.md | 9 +++++++-- main.py | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3bc2942..2063fe0 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ To make this project only you need to follow this step:- pip install folium pip install geocoder pip install opencage + pip install load_dotenv ``` ### Install package with pip (Mac) ``` @@ -30,7 +31,7 @@ python3 -m pip install phonenumbers python3 -m pip install folium python3 -m pip install geocoder python3 -m pip install opencage - +python3 -m pip install load_dotenv ``` Now need to collect Geocoder API Key from https://opencagedata.com/ @@ -47,8 +48,12 @@ Step3: From API Keys collect API key ![github3](https://user-images.githubusercontent.com/123636419/215339773-0171d38c-b9ad-490a-95d8-47366321048a.PNG) +### Set API key - +Create a `.env` file. In this file enter the following replacing `keyhere` with your API key: +``` +OPENCAGE_API_KEY=keyhere +``` ## Deployment diff --git a/main.py b/main.py index 5840da6..fa9c7a7 100644 --- a/main.py +++ b/main.py @@ -2,8 +2,11 @@ from phonenumbers import geocoder, carrier from opencage.geocoder import OpenCageGeocode import folium -import webbrowser # Import the webbrowser module to open the HTML file import os +from dotenv import load_dotenv + +# Load environment variables from .env file +load_dotenv() # Function to validate phone number format def validate_phone_number(number): @@ -18,7 +21,11 @@ def validate_phone_number(number): # Main function for location tracking def track_location(): - key = "d2b3af88e38b4b5bb6e04f77a89e39f3" # Replace with your OpenCage API Key + # Get OpenCage API Key from environment variable + opencage_api_key = os.getenv("OPENCAGE_API_KEY") ## Otherwise is -> opencage_api_key = "ENTERKEY" + if not opencage_api_key: + raise ValueError("OpenCage API Key not found. Please set it in the environment or in a .env file.") + number = input("Please enter the phone number (with country code): ") # Validate phone number format @@ -35,7 +42,7 @@ def track_location(): print(f"Service Provider: {service_name}") # Geocode using OpenCage API - geocoder_obj = OpenCageGeocode(key) + geocoder_obj = OpenCageGeocode(opencage_api_key) query = str(location) try: result = geocoder_obj.geocode(query) @@ -49,11 +56,11 @@ def track_location(): # Save map to HTML file html_file = "location.html" - file_path = os.path.abspath(html_file) # Get absolute file path - my_map.save(file_path) + my_map.save(html_file) # Open the HTML file in the default web browser - webbrowser.open('file://' + file_path, new=2) + import webbrowser + webbrowser.open('file://' + os.path.realpath(html_file)) print("Location tracking completed. Map saved and opened in browser.") else: From 8910a58e05b1e278cdf76799e72f88498c85fd92 Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Thu, 20 Jun 2024 10:46:47 +0100 Subject: [PATCH 5/7] tweaks --- main.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/main.py b/main.py index fa9c7a7..86e8bb7 100644 --- a/main.py +++ b/main.py @@ -70,6 +70,4 @@ def track_location(): print("Thank you") -# Run the main function -if __name__ == "__main__": - track_location() +track_location() From 6f27c938cc64aa37a1ed0952ce45c8c1e55fbf02 Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Thu, 20 Jun 2024 10:49:13 +0100 Subject: [PATCH 6/7] chore: updated README --- README.md | 40 +--------------------------------------- 1 file changed, 1 insertion(+), 39 deletions(-) diff --git a/README.md b/README.md index 2063fe0..cca8aac 100644 --- a/README.md +++ b/README.md @@ -56,45 +56,7 @@ OPENCAGE_API_KEY=keyhere ``` ## Deployment - -To deploy this project run - -```bash -import phonenumbers -from phonenumbers import geocoder -from phonenumbers import carrier -import opencage -from opencage.geocoder import OpenCageGeocode -import folium - - -key = "your key" #Geocoder API Key need to paste here "your key" -number = input("please giver your number: ") -new_number = phonenumbers.parse(number) -location = geocoder.description_for_number(new_number, "en") -print(location) - -service_name = carrier.name_for_number(new_number,"en") -print(service_name) - -geocoder = OpenCageGeocode(key) -query = str(location) -result = geocoder.geocode(query) -#print(result) - -lat = result[0]['geometry']['lat'] -lng = result[0]['geometry']['lng'] - -print(lat,lng) - -my_map = folium.Map(location=[lat,lng], zoom_start=9) -folium.Marker([lat, lng], popup= location).add_to(my_map) - -my_map.save("location.html") - -print("location tracking completed") -print("Thank you") -``` +Simply run the file `main.py`! You can follow me From f825e50e8346f0f0c1e6df2e55ddee9b34fe10d4 Mon Sep 17 00:00:00 2001 From: Tristan Hill Date: Thu, 20 Jun 2024 10:54:17 +0100 Subject: [PATCH 7/7] updated README with blog post --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index cca8aac..55b8aa1 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ OPENCAGE_API_KEY=keyhere ## Deployment Simply run the file `main.py`! +### Please note: +This cannot be used to accuratly locate someone phone number as per: [link](https://blog.opencagedata.com/post/we-can-not-convert-a-phone-number-into-a-location-sorry) + You can follow me