Skip to content

Commit c00f7b5

Browse files
author
Rodolfo Herrera
committed
Stable version
1 parent 261aa0f commit c00f7b5

File tree

4 files changed

+105
-75
lines changed

4 files changed

+105
-75
lines changed

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,17 @@
1-
# Phone-Number-Information
2-
This basic script written in the Python programming language, will allow you to know some things about an international telephone number, such as its approximate latitude and longitude, its location, its service provider etc ..., it will allow you to save all the data in a file, you also need a key to use the OpenCage API but the script comes with a KEY ready, just come and use, you can extend it as you want.
1+
## Phone Numbers Information
2+
##### A simple script to extract information from a phone number.
3+
4+
### Getting starting
5+
You only have to execute a series of commands in your terminal to initialize the script correctly, it is easier than you think.
6+
```bash
7+
# Cloning the repository
8+
git clone https://github.com/CodeWithRodi/Phone-Number-Information/
9+
# Entering the folder with the source code
10+
cd Phone-Number-Information
11+
# Installing the necessary modules
12+
pip install -r Requirements.txt
13+
# Starting the script
14+
python3 Script.py
15+
```
16+
17+
### Remember drink water my love.
File renamed without changes.

Script.py

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# ***
2+
# * Copyright (C) Rodolfo Herrera Hernandez. All rights reserved.
3+
# * Licensed under the MIT license. See LICENSE file in the project root
4+
# * for full license information.
5+
# *
6+
# * =+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+
7+
# *
8+
# * For related information - https://github.com/codewithrodi/Phone-Number-Information/
9+
# *
10+
# * =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
11+
# ****/
12+
13+
from opencage.geocoder import OpenCageGeocode
14+
from phonenumbers import ( geocoder, carrier, parse )
15+
from os import system
16+
17+
import platform
18+
19+
kOperativeSystem = platform.system()
20+
21+
def Main():
22+
print('''\
23+
=============== PHONE NUMBERS INFORMATION ===============
24+
* Developed by Rodolfo Herrera Hernandez
25+
* https://github.com/codewithrodi/
26+
* [email protected] - Full Stack Developer
27+
''')
28+
29+
print(':: Phone number example: +56 9 1122 3344')
30+
Number = input('/> Enter a phone number including the country code: ')
31+
32+
# https://opencagedata.com/ API KEY
33+
KEY = '3c3d3f1a27614afd86b3f64addc1ceb3'
34+
35+
ParsedNumber = parse(Number.replace(' ', ''))
36+
Country = geocoder.description_for_number(ParsedNumber, 'en')
37+
Service = carrier.name_for_number(ParsedNumber, 'en')
38+
39+
PhoneInformation = OpenCageGeocode(KEY).geocode(Country)
40+
Geometry = PhoneInformation[8]
41+
Latitude = Geometry['geometry']['lat']
42+
Longitude = Geometry['geometry']['lng']
43+
State = Geometry['components']['state']
44+
45+
Annotations = PhoneInformation[0]['annotations']
46+
Timezone = Annotations['timezone']['name']
47+
48+
Components = PhoneInformation[0]['components']
49+
CountryCode = Components['country_code']
50+
Continent = Components['continent']
51+
52+
Output = f'''
53+
=============== RESULTS ===============
54+
* Country: {Country} [{CountryCode.upper()}] [{Continent}]
55+
* State: {State} [Approximate]
56+
* Carrier: {Service}
57+
* Timezone: {Timezone}
58+
* Latitude: {Latitude} [Approximate]
59+
* Longitude: {Longitude} [Approximate]
60+
=======================================
61+
'''
62+
63+
print(Output)
64+
65+
SaveDataResponse = input('/> Do you want to save the information in a file?[y/N]: ')
66+
67+
if SaveDataResponse.upper() == 'Y':
68+
LogFile = open('Log.txt', 'a')
69+
LogFile.write(
70+
f'''\
71+
Information related to the number: {Number}
72+
{Output}\n''')
73+
print('\nInformation saved in [Log.txt]')
74+
LogFile.close()
75+
else:
76+
print('\n:: Gooooooodbye, drink water!')
77+
78+
def ClearScreen() -> None:
79+
system('cls' if kOperativeSystem == 'Windows' else 'clear')
80+
81+
if __name__ == '__main__':
82+
try:
83+
ClearScreen()
84+
Main()
85+
except KeyboardInterrupt:
86+
print('\n:: Remember drink water!')
87+
except Exception:
88+
print('\n:: An error occurred when trying to continue with the execution of the program, it is an unhandled exception was thrown.')

script.py

Lines changed: 0 additions & 73 deletions
This file was deleted.

0 commit comments

Comments
 (0)