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