Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hawqal python package #1

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
Empty file added __init__.py
Empty file.
Binary file added __pycache__/test.cpython-310.pyc
Binary file not shown.
Binary file added __pycache__/unittest.cpython-310.pyc
Binary file not shown.
Binary file added database/hawqalDB.sqlite
Binary file not shown.
Empty file added hawqal/__init__.py
Empty file.
Binary file added hawqal/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Empty file added hawqal/dal/__init__.py
Empty file.
Binary file added hawqal/dal/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added hawqal/dal/__pycache__/dao.cpython-310.pyc
Binary file not shown.
11 changes: 11 additions & 0 deletions hawqal/dal/dao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import sqlite3
import os


class Database:

def __init__(self, path):
self.databasePath = path

def makeConnection(self):
return sqlite3.connect(f"{self.databasePath}")
Empty file added hawqal/services/__init__.py
Empty file.
Binary file added hawqal/services/__pycache__/Country.cpython-310.pyc
Binary file not shown.
Binary file added hawqal/services/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added hawqal/services/__pycache__/cities.cpython-310.pyc
Binary file not shown.
Binary file not shown.
Binary file added hawqal/services/__pycache__/states.cpython-310.pyc
Binary file not shown.
Binary file not shown.
17 changes: 17 additions & 0 deletions hawqal/services/cities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from hawqal.dal.dao import Database


class City:

@staticmethod
def getCities():
cities = []
file_name = "database/hawqalDB.sqlite"
with open(file_name, 'r', encoding="utf8") as db:
database = Database(file_name).makeConnection()
cursor = database.cursor()
data = cursor.execute(
f"SELECT * FROM cities ORDER BY name ASC")
for row in data:
cities.append([row[1], row[4]])
return cities
19 changes: 19 additions & 0 deletions hawqal/services/citiesbycountry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from hawqal.dal.dao import Database
import string


class CitiesByCountry:

@staticmethod
def getCities(country):
states = []
country = string.capwords(country)
file_name = "database/hawqalDB.sqlite"
with open(file_name, 'r', encoding="utf8") as db:
database = Database(file_name).makeConnection()
cursor = database.cursor()
data = cursor.execute(
f'SELECT name FROM cities WHERE country_name = "{country}"')
for row in data:
states.append(f'{row[0]}')
return states
17 changes: 17 additions & 0 deletions hawqal/services/country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from hawqal.dal.dao import Database


class Country:

@staticmethod
def getCountries():
countries = []
file_name = "database/hawqalDB.sqlite"
with open(file_name, 'r', encoding="utf8") as db:
database = Database(file_name).makeConnection()
cursor = database.cursor()
data = cursor.execute(
f"SELECT * FROM countries ORDER BY country_id ASC")
for row in data:
countries.append(f'{row[1]}')
return countries
17 changes: 17 additions & 0 deletions hawqal/services/states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from hawqal.dal.dao import Database


class State:

@staticmethod
def getStates():
states = []
file_name = "database/hawqalDB.sqlite"
with open(file_name, 'r', encoding="utf8") as db:
database = Database(file_name).makeConnection()
cursor = database.cursor()
data = cursor.execute(
"SELECT * FROM states ORDER BY name ASC")
for row in data:
states.append([row[1], row[3]])
return states
19 changes: 19 additions & 0 deletions hawqal/services/statesbycountry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from hawqal.dal.dao import Database
import string


class StatesByCountry:

@staticmethod
def getStates(country):
states = []
country = string.capwords(country)
file_name = "database/hawqalDB.sqlite"
with open(file_name, 'r', encoding="utf8") as db:
database = Database(file_name).makeConnection()
cursor = database.cursor()
data = cursor.execute(
f'SELECT name FROM states WHERE country_name = "{country}"')
for row in data:
states.append(f'{row[0]}')
return states
13 changes: 13 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from hawqal.services.country import Country
from hawqal.services.states import State
from hawqal.services.cities import City
from hawqal.services.statesbycountry import StatesByCountry
from hawqal.services.citiesbycountry import CitiesByCountry

if __name__ == "__main__":

Country.getCountries()
State.getStates()
City.getCities()
StatesByCountry.getStates()
CitiesByCountry.getCities()
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#Python version 3.10.9
46 changes: 46 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Python setup.py for hawqal package"""
import io
import os
from setuptools import find_packages, setup


def read(*paths, **kwargs):
"""Read the contents of a text file safely.
>>> read("hawqal", "VERSION")
'0.1.0'
>>> read("README.md")
...
"""

content = ""
with io.open(
os.path.join(os.path.dirname(__file__), *paths),
encoding=kwargs.get("encoding", "utf8"),
) as open_file:
content = open_file.read().strip()
return content


def read_requirements(path):
return [
line.strip()
for line in read(path).split("\n")
if not line.startswith(('"', "#", "-", "git+"))
]


setup(
name="hawqal",
version=read("hawqal", "0.1.0"),
description="Python package that contains the data of world's countries,states and their cities name",
url="https://github.com/CapregSoft/Hawqal-python.git",
long_description=read("README.md"),
long_description_content_type="text/markdown",
author="capregsoft",
packages=find_packages(exclude=["tests", ".github"]),
install_requires=read_requirements("requirements.txt"),
entry_points={
"console_scripts": ["hawqal = hawqal.__main__:main"]
},
extras_require={"test": read_requirements("requirements.txt")},
)
30 changes: 30 additions & 0 deletions test_hawqal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import unittest
from hawqal.services.country import Country
from hawqal.services.states import State
from hawqal.services.cities import City
from hawqal.services.statesbycountry import StatesByCountry
from hawqal.services.citiesbycountry import CitiesByCountry


class TestFunc(unittest.TestCase):

def test_getCountries(self):
self.assertEqual(len(Country.getCountries()), 250)

def test_getStates(self):
self.assertEqual(len(State.getStates()), 4989)

def test_getCities(self):
self.assertEqual(len(City.getCities()), 150710)

def test_getStatesByCountry(self):
expected = len(StatesByCountry.getStates("Pakistan"))
self.assertEqual(len(StatesByCountry.getStates("Pakistan")), expected)

def test_getCitiesByCountry(self):
expected = len(CitiesByCountry.getCities("Pakistan"))
self.assertEqual(len(CitiesByCountry.getCities("Pakistan")), expected)


if __name__ == '__main__':
unittest.main()