Skip to content

CapregSoft/hawqal-web

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 

Repository files navigation

Introduction

The hawqal package is a library that provides a list of countries, states, and cities in the world. It is available in Node.js, Go, and Python.

Functionality

  • Get all countries
  • Get states by country
  • Get cities by country
  • Get cities by state

Go

Installation

To install Hawqal, run the following command:

go get github.com/CapregSoft/Hawqal-go

Functions

  • Get All Countries
  • Get All Cities
  • Get All States
  • Get State By Country
  • Get Cities By Country
  • Get Cities By State

Usage/Examples

Get Started

package main

import (
  "fmt"
   hawqal "gihtub.com/CapregSoft/Hawqal-go"
  "log"
)

Get All Countries

To get a list of all countries, use the hawqal.GetCountriesData() function whch returns countries & error.

  countries, err := hawqal.GetCountriesData()
  if err != nil {
    log.Fatalf("Error %v", err)
  }
  fmt.Print("Country")
  for _, country := range countries {
    fmt.Printf("ID :: %v - Country :: %v\n", *country.CountryID, *country.CountryName)
  }

Success Response

  {
    Countries : ['Afghanistan', 'Aland Islands', 'Albania', 'Algeria', . . . ]
  }

Get All Cities

To get a list of all cities, use the hawqal.GetCitiesData() function whch returns cities & error.

  cities, err := hawqal.GetCitiesData()
	if err != nil {
		log.Fatalf("Error %v", err)
	}

	fmt.Print("Cities")
	for _, city := range cities {
		fmt.Printf("City :: %v - Country :: %v \n", *city.CityName, *city.CountryName)
	}

Success Response

  {
    Cities : ['Haripur','Abbotabad','WahCantt','Topi',........]
  }

Get All States

To get a list of all states, use the hawqal.GetStatesData() function:

    states, err := hawqal.GetStatesData()
    if err != nil {
      log.Fatalf("Error %v", err)
    }

    fmt.Print("States")
    for _, state := range states {
      fmt.Printf("State :: %v - Country :: %v \n", *state.StateName, *state.CountryName)
    }

Success Response

{
  States : ['Alabama', 'Alaska', 'American Samoa', 'Arizona', . . . ]
}

Get States By Country Name

To get a list of states for a specific country, use the GetStatesByCountry function:

  statesByCountry, err := hawqal.GetStatesByCountry(countryName)
	if err != nil {
		log.Fatalf("Error %v", err)
	}
	fmt.Printf("states: %v  ", statesByCountry)

Success Response

{
  States : ['Alabama', 'Alaska', 'American Samoa', 'Arizona', . . . ]
}

Get Cities By Country

To get a list of cities for a specific country, use the GetCitiesByCountryData function:

  citiesByCountry, err := hawqal.GetCitiesByCountryData(citiesCountryName)
  if err != nil {
    log.Fatalf("Error %v", err)
  }
  fmt.Print("Cities For Country ", citiesCountryName)
  for _, city := range citiesByCountry {
    fmt.Printf("City :: %v \n", *city.CityName)
  }

Success Response

  {
    Cities : ['Haripur','Abbotabad','WahCantt','Topi',........]
  }

Get Cities By State

To get a list of cities for a specific state, use the GetCitiesByState function:

  citiesByState, err := hawqal.GetCitiesByState(stateName)
	if err != nil {
		log.Fatalf("Error %v", err)
	}

	fmt.Print("Cities For State ", stateName)
	for _, city := range citiesByState {
		fmt.Printf("City :: %v \n", *city.CityName)
	}

Success Response

{
  Cities : ['Haripur','Abbotabad','WahCantt','Topi',........]
}

Node Js

Installation

To install Hawqal, run the following command:

npm i @capregsoft/hawqal

Functions

  • Get Countries
  • Get Cities
  • Get States

Usage/Examples

Use Asyc and await to get meaningful response

All Countries

To get a list of all countries, use the getCountries function:

const worldData = require('@capregsoft/hawqal')
const getData = async () =>{
    console.log(await worldData.getCountries());
}
getData();

Success Response

 [
  'Afghanistan',
  'Aland Islands',
  'Albania',
  'Algeria',
  'American Samoa',
  'Andorra',
  'Angola',
  'Anguilla',...
]

All States

To get a list of all states, use the getStates function:

const worldData = require('@capregsoft/hawqal')
const getStates = async () =>{
    console.log(await await index.getStates('pakistan'));
}
getStates();

Success Response

[
  'Azad Kashmir',
  'Balochistan',
  'Federally Administered Tribal Areas',
  'Gilgit-Baltistan',
  'Islamabad Capital Territory',
  'Khyber Pakhtunkhwa',
  'Punjab',
  'Sindh'
]

Cities By State & Country Name

To get a list of cities for a specific state, cities or country, use the getCities parameterized function:

const worldData = require('@capregsoft/hawqal')
const getCities = async () =>{
     //get all cities
    console.log(await await index.getCities());

    //get state cities
    console.log(await await index.getCities('','punjab'));
    
    //get country cities
    console.log(await await index.getCities('pakistan'));
    
    //get country,state cities
    console.log(await await index.getCities('pakistan','punjab'));
}
getCities();

Success Response

[
  'Fatehgarh Sahib', 'Firozpur',     'Firozpur District',
  'Fazilka',         'Gardhiwala',   'Garhshankar',
  'Ghanaur',         'Giddarbaha',   'Gurdaspur',
  'Guru Har Sahai',  'Hariana',      'Hoshiarpur',
  'Hajipur',         'Jagraon',      'Jaito',
]

Error Response

[]

Db connection Error!!!

Python

To install the package in Python, run the following command:

Installation

  pip install hawqal

Functions

  • Getting a list of Countries
  • Getting a list of Cities
  • Getting a list of States
  • Getting Cities By Country
  • Getting Cities By State
  • Getting States by Country

Usage/Example

Getting a list of Countries

To get a list of all countries, you can use the getCountries() function.

  from hawqal.country import Country
  Country.getCountries()

Success Response

  ['Afghanistan', 'Aland Islands', 'Albania', 'Algeria', . . . ]

Getting a list of Cities

To get a list of all Cities, you can use the getCities() function.

  from hawqal.cities import City
  City.getCities("countries name", "state")

Success Response

  ['Haripur','Abbotabad','Topi',........]

Getting a list of States

To get a list of all States, you can use the getStates() function.

  from hawqal.states import StatesByCountry
  StatesByCountry.getStates()

Success Response

   ['Alabama', 'Alaska', 'American Samoa', 'Arizona', . . . ]

Getting Cities By Country

To get a list of all Countries, you can use the CitiesByCountry() function.

  from hawqal.citiesbycountry import CitiesByCountry
  CitiesByCountry.getCities("country name")

Success Response

   ['Haripur','Abbotabad','WahCantt','Topi',........]

Getting Cities By State

To get a list of all Cities By State, you can use the CitiesByCountry() function.

  from hawqal.cities import City
  City.getCities("", "state")

Success Response

   ['Haripur','Abbotabad','WahCantt','Topi',........]

Getting States by Country

To get a list of all states by country, you can use the CitiesByCountry() function.

  from hawqal.states import StatesByCountry
  StatesByCountry.getStates("country name")

Success Response

   ['Alabama', 'Alaska', 'American Samoa', 'Arizona', . . . ]

About

A documentation website about a package hawqal that is available in golang, python and node that gives us countries, states and name of their cities

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published