-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
.venv/ | ||
instance/ | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
__pycache__/ | ||
|
||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# VSCode settings | ||
.vscode/ | ||
|
||
# dotenv | ||
.env | ||
.env.* | ||
|
||
# virtualenv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
MIT License | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
|
||
Alex Mkwizu | ||
[email protected] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# nambazasimu/carrier_identifier.py | ||
|
||
def identify_carrier(phone_number): | ||
"""Identify the carrier of a given Tanzanian phone number""" | ||
#Check if the number is in either of the following correct formats "255XXXXXXXXX", "0XXXXXXXXX", "+255XXXXXXXXX" | ||
if phone_number.startswith("+255"): | ||
phone_number = phone_number[4:] | ||
elif phone_number.startswith("255"): | ||
phone_number = phone_number[3:] | ||
elif phone_number.startswith("0"): | ||
phone_number = phone_number[1:] | ||
|
||
#Defines carrier prefixes | ||
prefixes = { | ||
'Airtel' : ["68", "69", "78"], | ||
'Vodacom' : ["74", "75", "76"], | ||
'Tigo' : ["71", "65", "67"], | ||
'Zantel' : ["77"], | ||
'Halotel' : ["62"], | ||
'TTCL' : ["73"], | ||
'Smile' : ["66"] | ||
} | ||
|
||
#check the carrier | ||
for carrier, prefix_list in prefixes.items(): | ||
if any(phone_number.startswith(prefix) for prefix in prefix_list): | ||
return carrier | ||
|
||
return "Unknown" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-e git+https://github.com/genie360s/nambazasimu.git@089f0c93e8da566ccf7f3cb80a4c5b7a6493db04#egg=nambazasimu | ||
setuptools==70.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# setup.py | ||
|
||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name="nambazasimu", | ||
version="0.1.0", | ||
packages=find_packages(), | ||
install_requires=[], | ||
test_suite='tests', | ||
author="Alex Mkwizu", | ||
author_email="[email protected]", | ||
description="A package to identify Tanzanian phone number carriers.", | ||
long_description=open('README.md').read(), | ||
long_description_content_type='text/markdown', | ||
url="https://github.com/genie360s/nambazasimu", | ||
classifiers=[ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
], | ||
python_requires='>=3.6', | ||
) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# tests/test_carrier_identifier.py | ||
|
||
import unittest | ||
from nambazasimu.carrier_identifier import identify_carrier | ||
|
||
class TestCarrierIdentifier(unittest.TestCase): | ||
|
||
def test_airtel_numbers(self): | ||
self.assertEqual(identify_carrier("+255684567890"), "Airtel") | ||
self.assertEqual(identify_carrier("255685567890"), "Airtel") | ||
self.assertEqual(identify_carrier("0684567890"), "Airtel") | ||
self.assertEqual(identify_carrier("+255784567890"), "Airtel") | ||
self.assertEqual(identify_carrier("255785567890"), "Airtel") | ||
self.assertEqual(identify_carrier("0784567890"), "Airtel") | ||
self.assertEqual(identify_carrier("+255694567890"), "Airtel") | ||
self.assertEqual(identify_carrier("255695567890"), "Airtel") | ||
self.assertEqual(identify_carrier("0694567890"), "Airtel") | ||
|
||
def test_vodacom_numbers(self): | ||
self.assertEqual(identify_carrier("+255754567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("255755567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("075567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("+255764567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("255765567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("076567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("+255744567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("255745567890"), "Vodacom") | ||
self.assertEqual(identify_carrier("074567890"), "Vodacom") | ||
|
||
def test_tigo_numbers(self): | ||
self.assertEqual(identify_carrier("+255714567890"), "Tigo") | ||
self.assertEqual(identify_carrier("255715567890"), "Tigo") | ||
self.assertEqual(identify_carrier("071567890"), "Tigo") | ||
self.assertEqual(identify_carrier("+255654567890"), "Tigo") | ||
self.assertEqual(identify_carrier("255655567890"), "Tigo") | ||
self.assertEqual(identify_carrier("065567890"), "Tigo") | ||
self.assertEqual(identify_carrier("+255674567890"), "Tigo") | ||
self.assertEqual(identify_carrier("255675567890"), "Tigo") | ||
self.assertEqual(identify_carrier("067567890"), "Tigo") | ||
|
||
def test_zantel_numbers(self): | ||
self.assertEqual(identify_carrier("+255774567890"), "Zantel") | ||
self.assertEqual(identify_carrier("255775567890"), "Zantel") | ||
self.assertEqual(identify_carrier("077567890"), "Zantel") | ||
|
||
def test_halotel_numbers(self): | ||
self.assertEqual(identify_carrier("+255624567890"), "Halotel") | ||
self.assertEqual(identify_carrier("255625567890"), "Halotel") | ||
self.assertEqual(identify_carrier("062567890"), "Halotel") | ||
|
||
def test_ttcl_numbers(self): | ||
self.assertEqual(identify_carrier("+255734567890"), "TTCL") | ||
self.assertEqual(identify_carrier("255735567890"), "TTCL") | ||
self.assertEqual(identify_carrier("073567890"), "TTCL") | ||
|
||
def test_smile_numbers(self): | ||
self.assertEqual(identify_carrier("+255664567890"), "Smile") | ||
self.assertEqual(identify_carrier("255665567890"), "Smile") | ||
self.assertEqual(identify_carrier("066567890"), "Smile") | ||
|
||
def test_unknown_numbers(self): | ||
self.assertEqual(identify_carrier("+255804567890"), "Unknown") | ||
self.assertEqual(identify_carrier("255805567890"), "Unknown") | ||
self.assertEqual(identify_carrier("080567890"), "Unknown") | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |