Skip to content

Commit

Permalink
Merge pull request #48 from razorpay/release/1.0.12
Browse files Browse the repository at this point in the history
Release/1.0.12
  • Loading branch information
patlola committed Dec 23, 2017
2 parents b0f7d14 + 26acd0f commit 70080e3
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ifsc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

Gem::Specification.new do |s|
s.name = 'ifsc'
s.version = '1.0.11'
s.version = '1.0.12'
s.date = '2017-11-20'
s.summary = 'IFSC code database to help you validate IFSC codes'
s.description = 'A simple gem by @razorpay to help you validate your IFSC codes. IFSC codes are bank codes within India'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ifsc",
"version": "1.0.11",
"version": "1.0.12",
"description":
"This is part of the IFSC toolset released by Razorpay. You can find more details about the entire release at [ifsc.razorpay.com](https://ifsc.razorpay.com). Includes only a validation library as of now.",
"main": "src/node/index.js",
Expand Down
7 changes: 6 additions & 1 deletion scraper/scripts/bootstrap.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ IFS=$'\n\t'
mkdir --parents data
mkdir --parents sheets

# # Sublet listing comes from NPCI
# Sublet listing comes from NPCI
wget "https://www.npci.org.in/national-automated-clearing-live-members-1" --output-document=nach.html --user-agent="Firefox"
bundle exec ruby parse_nach.rb

Expand All @@ -17,14 +17,19 @@ wget --verbose "$RBI_LIST_URL" --output-document=list.html
bundle exec ruby parse_list.rb > excel_list.txt
rm --recursive --force sheets


# Cache the downloaded files
if [ -z "$WERCKER_CACHE_DIR" ]; then
# A few files return a 404, so we force true here
wget --timestamping --no-verbose --input-file=excel_list.txt --directory-prefix=sheets/ || true
# RTGS codes from https://rbi.org.in/scripts/FAQView.aspx?Id=65
wget "https://rbidocs.rbi.org.in/rdocs/RTGS/DOCs/RTGEB0815.XLSX" --output-document="sheets/RTGS.xlsx" || true
else
# Make sure we have a cache
mkdir -p "$WERCKER_CACHE_DIR/sheets"
wget --timeout=5 --timestamping --verbose --input-file=excel_list.txt --directory-prefix="$WERCKER_CACHE_DIR/sheets/" || true
# RTGS codes from https://rbi.org.in/scripts/FAQView.aspx?Id=65
wget "https://rbidocs.rbi.org.in/rdocs/RTGS/DOCs/RTGEB0815.XLSX" --output-document="$WERCKER_CACHE_DIR/sheets/RTGS.xlsx" || true
# Copy back to the cache if the download worked
cp --recursive --preserve=timestamps "$WERCKER_CACHE_DIR/sheets" .
fi
Expand Down
11 changes: 7 additions & 4 deletions scraper/scripts/generate.rb
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
require './methods'

data, file_ifsc_mappings = parse_sheets()
rtgs_data = parse_rtgs()
ifsc_data = parse_sheets()

hash = Hash.new
data.each { |row| hash[row['IFSC']] = row }
ifsc_codes_list = hash.keys
# Using IFSC data and marking rtgs=true for the applicable ifsc's

data, hash = parse_ifsc_rtgs(ifsc_data, rtgs_data)

if File.exists? 'sheets/SUBLET.xlsx'
sublet_data = parse_sublet_sheet()
log "Exporting Sublet JSON"
export_sublet_json(sublet_data)
end

ifsc_codes_list = hash.keys

log "Exporting CSV"
export_csv(data)

Expand Down
76 changes: 70 additions & 6 deletions scraper/scripts/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ def parse_sublet_json()
def parse_sheets
data = []

file_ifsc_mappings = Hash.new

Dir.glob('sheets/IFCB*') do |file|
log "Parsing #{file}"
basename = File.basename file
Expand All @@ -53,7 +51,6 @@ def parse_sheets
end
end
data.push x
file_ifsc_mappings[basename] = x['IFSC'][0..3]
rescue Exception => e
puts "Faced an Exception"
puts data_to_insert.to_json
Expand All @@ -77,7 +74,6 @@ def parse_sheets
begin
x = data_to_insert.transpose.to_h
data.push x
file_ifsc_mappings[basename] = x['IFSC'][0..3]
rescue Exception => e
puts "Faced an Exception"
puts data_to_insert.to_json
Expand All @@ -88,7 +84,41 @@ def parse_sheets
puts "[+] #{row_index} rows processed"
end
end
[data, file_ifsc_mappings]
data
end

def parse_rtgs
data = []

log "Parsing #RTGS.xlsx"
sheet = RubyXL::Parser.parse("sheets/RTGS.xlsx").worksheets[1]
headings = sheet.sheet_data[0]
headings = (0..9).map {|e| headings[e].value}
row_index = 0
sheet.each do |row|
row_index += 1
# sanitize row
row = (0..9).map { |e| row[e] ? row[e].value : nil}
next if row_index == 1
next if row.compact.empty?

data_to_insert = [HEADINGS_INSERT, map_data(row, headings)]
begin
x = data_to_insert.transpose.to_h
# IFSC values are in smaller case
x["IFSC"] = x["IFSC"].upcase
# RTGS Flag
x["RTGS"] = true
data.push x
rescue Exception => e
puts "Faced an Exception"
puts data_to_insert.to_json
puts e
exit
end
end
puts "[+] #{row_index} rows processed"
data
end

def map_data(row, headings)
Expand All @@ -100,7 +130,8 @@ def map_data(row, headings)
'CENTRE' => 'CITY',
'CONTACT1' => 'CONTACT',
'IFSC CODE' => 'IFSC',
'BRANCH NAME' => 'BRANCH'
'BRANCH NAME' => 'BRANCH',
'BANK NAME' => 'BANK',
}
# Find the heading in HEADINGS_INSERT
headings.each_with_index do |header, heading_index|
Expand Down Expand Up @@ -220,6 +251,39 @@ def make_ranges(list)
ranges.map { |x| x.size==1 ? x[0] : x }
end

def parse_ifsc_rtgs(data_ifsc, data_rtgs)
ifsc = Hash.new
rtgs = Hash.new
hash = Hash.new

data_ifsc.each { |row| ifsc[row['IFSC']] = row }
ifsc_keys = ifsc.keys

data_rtgs.each { |row| rtgs[row['IFSC']] = row }
rtgs_keys = rtgs.keys

data = []

rtgs.each do |key, value|
if not ifsc_keys.include? key
# already RTGS = true will be there in value
data.push(value)
end
end

ifsc.each do |key, value|
ifsc = value
if rtgs_keys.include? key
value['RTGS'] = true
end
data.push(value)
end

data.each { |row| hash[row['IFSC']] = row }

[data, hash]
end

def export_to_code_json(list, ifsc_hash)
banks = find_bank_codes list
banks_hash = Hash.new
Expand Down
2 changes: 2 additions & 0 deletions scraper/scripts/parse_nach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
'SKSB0000001',
# UFSB and UJVN are the same
'UJVN0000001',
# PKGB and PKGX are the same
'PKGB0000001',
]

doc.css('table')[0].css('tr').each do |row|
Expand Down
2 changes: 1 addition & 1 deletion src/IFSC.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/banknames.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@
"GUOX": "Gurgaon Central Co-operative Bank",
"HAMX": "Hamirpur District Co-operative Bank",
"HANX": "Hanumangarh Kendriya Sahakari Bank",
"HARC": "Haryana State Co-operative Apex Bank",
"HCBL": "HASTI Co-operative Bank",
"HCBL": "Hindusthan Co-operative Bank",
"HCBX": "Hasti Co-operative Bank",
Expand Down Expand Up @@ -765,6 +766,7 @@
"NDDX": "Nadia District Central Co-operative Bank",
"NDGX": "Nashik District Girna Sahakari Bank( Under Rbi Direction)",
"NDIX": "Nashik District Industrial & Mercantile Co-operative Bank",
"NESF": "North East Small Finance Bank",
"NEYX": "Neyyattinkara Co-operative Urban Bank",
"NGBX": "Nagar Sahakari Bank Maharajganj",
"NGKX": "Nagrik Sahakari Bank Maryadit Gwalior",
Expand Down Expand Up @@ -896,6 +898,7 @@
"PWUX": "Parwanoo Urban Co-operative Bank",
"PYCX": "Payyoli Co-operative Urban Bank",
"PYTM": "Paytm Payments Bank",
"QNBA": "Qatar National Bank Saq",
"QUCX": "Quilon Co-operative Urban Bank",
"RABO": "Rabobank International",
"RACX": "Rajkot Commercial Co-operative Bank",
Expand Down
3 changes: 3 additions & 0 deletions src/php/Bank.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ class Bank
const GUOX = 'GUOX';
const HAMX = 'HAMX';
const HANX = 'HANX';
const HARC = 'HARC';
const HCBL = 'HCBL';
const HCBX = 'HCBX';
const HCCX = 'HCCX';
Expand Down Expand Up @@ -767,6 +768,7 @@ class Bank
const NDDX = 'NDDX';
const NDGX = 'NDGX';
const NDIX = 'NDIX';
const NESF = 'NESF';
const NEYX = 'NEYX';
const NGBX = 'NGBX';
const NGKX = 'NGKX';
Expand Down Expand Up @@ -898,6 +900,7 @@ class Bank
const PWUX = 'PWUX';
const PYCX = 'PYCX';
const PYTM = 'PYTM';
const QNBA = 'QNBA';
const QUCX = 'QUCX';
const RABO = 'RABO';
const RACX = 'RACX';
Expand Down
1 change: 0 additions & 1 deletion src/sublet.json
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,6 @@
"KSCB0701001": "DVDX",
"MAHB000CB01": "COLX",
"MAHB0RRBMGB": "MGBX",
"PKGB0000001": "PGBX",
"PMEC0USVSBL": "SVSX",
"PSIB0SGB002": "SJGX",
"PUCB0000002": "PDUX",
Expand Down

0 comments on commit 70080e3

Please sign in to comment.