forked from tomiiide/nigerian-banks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request tomiiide#2 from victor-iyiola/master
Added Python, Go support
- Loading branch information
Showing
4 changed files
with
182 additions
and
3 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
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,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) | ||
} | ||
|
||
} |
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
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,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) |