Code Monkey home page Code Monkey logo

location-tracker's Introduction

Location-tracker

Location Tracker is a simple application that allows you to track the country of any phone number using the phone number's country code. It is written in Python and uses the pycountry and phone_iso3166 libraries for looking up country information based on the phone number.

To use this code in Jupyter Notebook, follow these steps:

  1. Install the required libraries: pycountry and phone_iso3166.
pip install pycountry
pip install phone-iso3166
  1. Copy the code for the Location Tracker application into a code cell in Jupyter Notebook.

  2. Run the code cell to define the Location_Tracker class and create an instance of it called MyApp.

  3. Run the next cell which calls PhoneTracker.mainloop() to run the Tkinter event loop and display the application.

  • Below is an example of a screenshot from the Application that is displayed

  1. Enter a phone number into the application's input field and click the Track Country button. The country associated with the phone number's country code will be displayed in the application's output label.
  • Here is the screenshot of the Application output after entering a valid phone number

Here's a breakdown of the code:

  1. Import the required libraries: json, pycountry, Tkinter, and phone_iso3166.

  2. Define a class called Location_Tracker that represents the application. In the init() method, create the application window and its widgets (a label, an entry field for the phone number, a button to track the country, and a label to display the output).

  3. Define a method called Track_location() that is called when the Track Country button is clicked. This method retrieves the phone number entered by the user, looks up the corresponding country using pycountry and phone_iso3166 libraries, and updates the output label with the name of the country.

  4. Define an instance of the Location_Tracker class called MyApp and run the mainloop() method of the Tkinter module to start the application's event loop.

  5. When the Track Country button is clicked, the Track_location() method is called, which retrieves the phone number entered by the user, looks up the corresponding country using pycountry and phone_iso3166 libraries, and updates the output label with the name of the country.

Breakdown of the classes and functions used in the code:

Classes

Location_Tracker This is the main class that contains all the GUI elements of the application. The constructor takes a single argument App which is the main Tk object. It initializes the various labels, buttons and entry widgets needed for the application and places them on the window.

It also defines a method Track_location that is bound to the track button. This method gets the phone number from the entry widget and calls the phone_country function to get the country code. It then uses the pycountry module to get the country name from the code and updates the country label on the GUI.

Functions

phone_country This function takes a phone number as input and returns the country code based on the number. It does this by first extracting the digits from the number using a regular expression. It then uses a dictionary to map the first few digits to the corresponding country code. If the number is not found in the dictionary, it returns Unknown. If there is an error while processing the number, it raises an InvalidPhone exception.

Other modules

pycountry This is a third-party module that provides data on countries such as their codes and names. It is used to get the name of the country from the country code returned by phone_country.

tkinter This is a standard Python module that provides a GUI toolkit for Python. It is used to create the GUI elements such as the labels, buttons and entry widget.

phone_iso3166 This is a third-party module that provides a mapping between phone number prefixes and country codes. It is used by the phone_country function to get the country code from the phone number.

location-tracker's People

Contributors

antonygn avatar

Stargazers

 avatar  avatar

Watchers

 avatar

location-tracker's Issues

Phone number validation

Note: This code assumes that the phone number entered by the user is valid and has a valid country code. If the phone number is invalid or has an invalid country code, the application will display an error message.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.