Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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__/
10 changes: 10 additions & 0 deletions dal/dao.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import sqlite3


class Database:

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

def makeConnection(self):
return sqlite3.connect(f"{self.databasePath}")
Binary file added database/hawqalDB.sqlite
Binary file not shown.
Empty file added hawqal/__init__.py
Empty file.
20 changes: 20 additions & 0 deletions hawqal/cities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from dal.dao import Database
import string


class City:

@staticmethod
def getCities(country, state):
cities = []
country = string.capwords(country)
state = string.capwords(state)
file_name = "/hawqal/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 cities.name FROM cities,states WHERE cities.state_id=states.state_id AND states.name = '{state}' AND states.country_name = '{country}'")
for row in data:
cities.append([row[0]])
return cities
19 changes: 19 additions & 0 deletions hawqal/citiesbycountry.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from dal.dao import Database
import string


class CitiesByCountry:

@staticmethod
def getCities(country):
states = []
country = string.capwords(country)
file_name = "/hawqal/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
18 changes: 18 additions & 0 deletions hawqal/country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from dal.dao import Database


class Country:

@staticmethod
def getCountries():
countries = []
file_name = "/hawqal/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

21 changes: 21 additions & 0 deletions hawqal/states.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from dal.dao import Database
import string


class StatesByCountry:

@staticmethod
def getStates(country):
states = []
country = string.capwords(country)
file_name = "/hawqal/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

print(StatesByCountry.getStates("united states"))
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
16 changes: 16 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""Python setup.py for hawqal package"""
from setuptools import find_packages, setup


setup(
name="hawqal",
version="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_content_type="text/markdown",
author="capregsoft",
packages=find_packages(exclude=["tests", ".github"]),
entry_points={
"console_scripts": ["hawqal = hawqal.__main__:main"]
},
)
26 changes: 26 additions & 0 deletions test/test_hawqal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest
from hawqal.country import Country
from hawqal.states import StatesByCountry
from hawqal.cities import City
from hawqal.citiesbycountry import CitiesByCountry


class TestFunc(unittest.TestCase):

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

def test_getStates(self):
self.assertEqual(len(StatesByCountry.getStates("Pakistan")), 8)

def test_getCities(self):
self.assertEqual(len(City.getCities("Pakistan", "Punjab")), 214)

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


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