Skip to content

Commit

Permalink
Merge pull request tomiiide#2 from victor-iyiola/master
Browse files Browse the repository at this point in the history
Added Python, Go support
  • Loading branch information
tomiiide authored Sep 24, 2018
2 parents 9964a9a + 6df0b6e commit cb0884d
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 3 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Here they are.

[JSON](https://github.com/tomiiide/nigerian-banks/raw/master/banks.json)

[Python](https://github.com/tomiiide/nigerian-banks/raw/master/banks.py)

[Go](https://github.com/tomiiide/nigerian-banks/raw/master/banks.go)

[PHP Array](https://github.com/tomiiide/nigerian-banks/raw/master/banks.php)

Don't hesitate to send a PR if you want to contribute. :v: & :heart:
Don't hesitate to send a PR if you want to contribute. :v: & :heart:
63 changes: 63 additions & 0 deletions banks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Package main implements list of Nigerian bank in Go.
//
// @author
// Victor I. Afolabi
// Artificial Intelligence & Software Engineer.
// Email: [email protected]
// GitHub: https://github.com/victor-iyiola
//
// @project
// File: banks.py
// Created on 24 September, 2018 @ 01:52 AM.
//
// @license
// MIT License
// Copyright (c) 2018. Victor I. Afolabi. All rights reserved.
package main

import "fmt"

// Bank represent structure for each bank object.
type Bank struct {
ID uint // Bank index/id.
Code string // Bank USSD code.
Name string // Bank name.
}

// Banks creates and array of Bank objects.
func Banks() []*Bank {
return []*Bank{&Bank{ID: 1, Code: "044", Name: "Access Bank"},
&Bank{ID: 2, Code: "023", Name: "Citibank"},
&Bank{ID: 3, Code: "063", Name: "Diamond Bank"},
&Bank{ID: 4, Code: "", Name: "Dynamic Standard Bank"},
&Bank{ID: 5, Code: "050", Name: "Ecobank Nigeria"},
&Bank{ID: 6, Code: "070", Name: "Fidelity Bank Nigeria"},
&Bank{ID: 7, Code: "011", Name: "First Bank of Nigeria"},
&Bank{ID: 8, Code: "214", Name: "First City Monument Bank"},
&Bank{ID: 9, Code: "058", Name: "Guaranty Trust Bank"},
&Bank{ID: 10, Code: "030", Name: "Heritage Bank Plc"},
&Bank{ID: 11, Code: "301", Name: "Jaiz Bank"},
&Bank{ID: 12, Code: "082", Name: "Keystone Bank Limited"},
&Bank{ID: 13, Code: "101", Name: "Providus Bank Plc"},
&Bank{ID: 14, Code: "076", Name: "Skye Bank"},
&Bank{ID: 15, Code: "221", Name: "Stanbic IBTC Bank Nigeria Limited"},
&Bank{ID: 16, Code: "068", Name: "Standard Chartered Bank"},
&Bank{ID: 17, Code: "232", Name: "Sterling Bank"},
&Bank{ID: 18, Code: "100", Name: "Suntrust Bank Nigeria Limited"},
&Bank{ID: 19, Code: "032", Name: "Union Bank of Nigeria"},
&Bank{ID: 20, Code: "033", Name: "United Bank for Africa"},
&Bank{ID: 21, Code: "215", Name: "Unity Bank Plc"},
&Bank{ID: 22, Code: "035", Name: "Wema Bank"},
&Bank{ID: 23, Code: "057", Name: "Zenith Bank"}}
}

func main() {
// banks contains array of Bank objects.
banks := Banks()

// Loop through each banks and print their props out.
for _, bank := range banks {
fmt.Println(bank.ID, bank.Code, bank.Name)
}

}
3 changes: 1 addition & 2 deletions banks.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//.banks
[
[
{ "id": "1", "name": "Access Bank" ,"code":"044" },
{ "id": "2", "name": "Citibank","code":"023" },
{ "id": "3", "name": "Diamond Bank","code":"063" },
Expand Down
113 changes: 113 additions & 0 deletions banks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
"""Nigerian banks list in Python.
@author
Victor I. Afolabi
Artificial Intelligence & Software Engineer.
Email: [email protected]
GitHub: https://github.com/victor-iyiola
@project
File: banks.py
Created on 24 September, 2018 @ 01:12 AM.
@license
MIT License
Copyright (c) 2018. Victor I. Afolabi. All rights reserved.
"""
import json

try:
# For Python 3.0 and later
from urllib.request import urlopen
except ImportError:
# Fall back to Python 2's urllib2
from urllib2 import urlopen

from typing import Union
from collections import namedtuple


# Single bank template.
Bank = namedtuple('Bank', ['id', 'name', 'code'])

# Nigerian bank list.
Banks = [
Bank(id=1, code='044', name='Access Bank'),
Bank(id=2, code='023', name='Citibank'),
Bank(id=3, code='063', name='Diamond Bank'),
Bank(id=4, code='', name='Dynamic Standard Bank'),
Bank(id=5, code='050', name='Ecobank Nigeria'),
Bank(id=6, code='070', name='Fidelity Bank Nigeria'),
Bank(id=7, code='011', name='First Bank of Nigeria'),
Bank(id=8, code='214', name='First City Monument Bank'),
Bank(id=9, code='058', name='Guaranty Trust Bank'),
Bank(id=10, code='030', name='Heritage Bank Plc'),
Bank(id=11, code='301', name='Jaiz Bank'),
Bank(id=12, code='082', name='Keystone Bank Limited'),
Bank(id=13, code='101', name='Providus Bank Plc'),
Bank(id=14, code='076', name='Skye Bank'),
Bank(id=15, code='221', name='Stanbic IBTC Bank Nigeria Limited'),
Bank(id=16, code='068', name='Standard Chartered Bank'),
Bank(id=17, code='232', name='Sterling Bank'),
Bank(id=18, code='100', name='Suntrust Bank Nigeria Limited'),
Bank(id=19, code='032', name='Union Bank of Nigeria'),
Bank(id=20, code='033', name='United Bank for Africa'),
Bank(id=21, code='215', name='Unity Bank Plc'),
Bank(id=22, code='035', name='Wema Bank'),
Bank(id=23, code='057', name='Zenith Bank')
]


def from_JSON(path: str) -> Union[list, dict]:
"""Parse bank list from a JSON file.
Provide a path to a JSON file. Example: `bank.json` found on
<https://github.com/tomiiide/nigerian-banks/bank.json>
Arguments:
path {str} -- Path to a JSON file containing bank names.
Returns:
Union[list, dict] -- List of banks depending on json format.
"""
return json.load(open(path))


def from_URL(url: str) -> Union[list, dict]:
"""Parse bank list from a given URL.
Provide a URL to a JSON file. Example: `bank.json` found on
<https://github.com/tomiiide/nigerian-banks/bank.json>
Arguments:
url {str} -- URL containing JSON data with bank (any) data.
Returns:
Union[list, dict] -- List of banks depending on json format.
"""
# Download JSON file.
response = urlopen(url)
data = response.read().decode('utf-8')

return json.loads(data)


if __name__ == '__main__':
# Demo: using `Banks`.
for bank in Banks:
print(bank.id, bank.code, bank.name)

# Line break.
print('=' * 45, '\n')

# Getting banks from a JSON file.
banks = from_JSON('banks.json')
for bank in banks:
print(bank['id'], bank['code'], bank['name'])

# # Getting Bank data from URL.
# url = ('https://raw.githubusercontent.com/tomiiide/'
# 'nigerian-banks/master/banks.json')
# url_banks = from_URL(url)
# for u_bank in url_banks:
# print(u_bank)

0 comments on commit cb0884d

Please sign in to comment.