Skip to content

Commit

Permalink
Merge pull request #220 from razorpay/release/1.5.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemo committed Apr 14, 2021
2 parents 66d29aa + 9a85916 commit 2f9e9dc
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 38 deletions.
8 changes: 4 additions & 4 deletions scraper/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ GEM
remote: https://rubygems.org/
specs:
mini_portile2 (2.5.0)
nokogiri (1.11.1)
nokogiri (1.11.3)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
racc (1.5.2)
ruby-ole (1.2.12.2)
rubyXL (3.4.16)
rubyXL (3.4.17)
nokogiri (>= 1.10.8)
rubyzip (>= 1.3.0)
rubyzip (2.3.0)
spreadsheet (1.2.7)
spreadsheet (1.2.8)
ruby-ole

PLATFORMS
Expand All @@ -23,4 +23,4 @@ DEPENDENCIES
spreadsheet

BUNDLED WITH
2.2.6
2.2.16
89 changes: 82 additions & 7 deletions scraper/scripts/methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@
STATE
].freeze

# These are not all the known states
# because the usage is quite limited for now
KNOWN_STATES = [
'ANDHRA PRADESH',
'DELHI',
'GUJARAT',
'JAMMU AND KASHMIR',
'HIMACHAL PRADESH',
'KARNATAKA',
'KERALA',
'MAHARASHTRA',
'PUNJAB',
'TAMIL NADU',
'MADHYA PRADESH',
'UTTARAKHAND',
'RAJASTHAN',
'TELANGANA',
'WEST BENGAL'
].freeze

def parse_imps(banks)
data = {}
banknames = JSON.parse File.read('../../src/banknames.json')
Expand Down Expand Up @@ -84,6 +104,50 @@ def parse_neft(banks)
data
end

# Some rows have last 2 columns shifted by 2
# Check for numeric values of STATE in RTGEB0815.xlsx for examples
# This checks and fixes those
def fix_row_alignment_for_rtgs(row)
# List of recognized states
unless KNOWN_STATES.include? row['CITY2'].to_s.strip
log "#{row['IFSC']} has an unknown state (#{row['CITY2']}), please check"
exit 1
end
# Start right shifting from the right-most column
row['PHONE'] = row['STD CODE']
# Move STATE's numeric value to STD CODE
row['STD CODE'] = row['STATE']
row['STATE'] = row['CITY2']
# Fix CITY2 value by duplicating CITY1
row['CITY2'] = row['CITY1']
return row
end

# Parses the contact details on the RTGS Sheet
def rtgs_parse_contact(std_code, phone)
scan_contact = phone.to_s.gsub(/[\s-]/, '').scan(/^(\d+)\D?/).last
scan_std_code = std_code.to_s.gsub(/[\s-]/, '').scan(/^(\d+)\D?/).last

contact = scan_contact.nil? || (scan_contact == 0) || (scan_contact == '0') || (scan_contact.is_a?(Array) && (scan_contact == ['0'])) ? nil : scan_contact.first
std_code = scan_std_code.nil? || (scan_std_code == 0) || (scan_std_code == '0') || (scan_std_code.is_a?(Array) && (scan_std_code == ['0'])) ? nil : scan_std_code.first

# If std code starts with 0, strip that out
if std_code and std_code[0] == '0'
std_code = std_code[1..]
end

# If we have an STD code, use it correctly
# Formatting as per E.164 format
# https://en.wikipedia.org/wiki/E.164
if std_code
return "+91#{std_code}#{contact}"
elsif contact
return "+91#{contact}"
else
return nil
end
end

def parse_rtgs(banks)
data = {}
sheets = 1..2
Expand All @@ -96,10 +160,12 @@ def parse_rtgs(banks)
micr_match = row['MICR_CODE'].to_s.strip.match('\d{9}')
row['MICR'] = micr_match[0] if micr_match
row['BANK'] = row.delete('BANK NAME')
row.delete('Date')
row.delete('MICR_CODE')
scan_contact = row['CONTACT'].to_s.gsub(/[\s-]/, '').scan(/^(\d+)\D?/).last
row['CONTACT'] = scan_contact.nil? || (scan_contact == 0) || (scan_contact == '0') || (scan_contact.is_a?(Array) && (scan_contact == ['0'])) ? nil : scan_contact.first

if row['STATE'].to_s.strip.match('\d')
row = fix_row_alignment_for_rtgs(row)
end

row['CONTACT'] = rtgs_parse_contact(row['STD CODE'], row['PHONE'])

# There is a second header in the middle of the sheet.
# :facepalm: RBI
Expand Down Expand Up @@ -128,9 +194,18 @@ def parse_rtgs(banks)
end
row['ADDRESS'] = row['ADDRESS'].to_s.strip
row['RTGS'] = true
# This is fallback option and we fake it
# because the RTGS sheet does not have the CITY
row['CITY'] = row['CENTRE']
# This isn't accurate sadly, because RBI has both the columns
# all over the place. As an example, check LAVB0000882 vs LAVB0000883
# which have the flipped values for CITY1 and CITY2
row['CITY'] = row['CITY2']
row['CENTRE'] = row['CITY1']
row['DISTRICT'] = row['CITY1']
# Delete rows we don't want in output
# Merged into CONTACRT
row.delete('STD CODE')
row.delete('PHONE')
row.delete('CITY1')
row.delete('CITY2')
data[row['IFSC']] = row
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/IFSC.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/banknames.json
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@
"JSVX": "Jila Sahakari Kendriya Bank Maryadit Shivpuri",
"JSWX": "Jansewa Urban Co-operative Bank",
"JTIX": "Jila Sahakari Kendriya Bank Mydt Tikamgarh",
"JTSC": "Janatha Seva Co-operative Bank",
"JTSX": "Jugalkishor Tapdiya Shree Mahesh Ucb Aurangabadltd",
"JUCX": "Junagadh Commercial Co-operative Bank",
"JUSX": "Jaysingpur Udgaon Sahakari Bank Jaysingpur",
Expand Down Expand Up @@ -760,7 +761,7 @@
"MOUX": "Mohol Urban Co-operative Bank",
"MPCX": "Moirang Primary Co-operative Bank",
"MPDX": "Malappuram District Co-operative Bank",
"MPRX": "Madhtya Pradesh Rajya Sahakari Bank Maryadit",
"MPRX": "Madhya Pradesh Rajya Sahakari Bank Maryadit",
"MRBX": "Manipur Rural Bank",
"MRTX": "Maratha Co-operative Bank",
"MSAX": "Mansarovar Urban Co-operative Bank",
Expand Down Expand Up @@ -969,6 +970,7 @@
"RBBX": "Rajarambapu Sahakari Bank Peth",
"RBCX": "Reserve Bank Employees Co-operative Bank",
"RBIN": "Reserve Bank Of India",
"RBIP": "Reserve Bank of India",
"RBIS": "Reserve Bank of India",
"RBIH": "IDRBT",
"RCBX": "Raniganj Co-operative Bank",
Expand Down Expand Up @@ -1071,6 +1073,7 @@
"SDTC": "Shri D T Patil Co-operative Bank",
"SDTX": "Sambalpur District Co-operative Central Bank",
"SDUX": "Sri Sudha Co-operative Bank",
"SECB": "Sree Charan Souhardha Co-operative Bank",
"SEMX": "Secunderabad Mercantile Co-operative Urban Bank",
"SENX": "Sehore Nagrik Sahakari Bank Sehore",
"SEUX": "Sevalia Urban Co-operative Bank",
Expand Down
42 changes: 25 additions & 17 deletions src/banks.json
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"ADBX": {
"code": "ADBX",
Expand Down Expand Up @@ -198,7 +199,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"ADCX": {
"code": "ADCX",
Expand Down Expand Up @@ -856,7 +858,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"ASSX": {
"code": "ASSX",
Expand Down Expand Up @@ -2539,8 +2542,7 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": true,
"upi": true
"nach_debit": true
},
"COSB": {
"code": "COSB",
Expand Down Expand Up @@ -7034,7 +7036,8 @@
"apbs": false,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"MAWX": {
"code": "MAWX",
Expand Down Expand Up @@ -7255,7 +7258,8 @@
"apbs": false,
"ach_credit": true,
"ach_debit": false,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"MDPX": {
"code": "MDPX",
Expand Down Expand Up @@ -7630,7 +7634,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"MRBX": {
"code": "MRBX",
Expand Down Expand Up @@ -8191,7 +8196,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"NEYX": {
"code": "NEYX",
Expand Down Expand Up @@ -8656,7 +8662,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"NUCB": {
"code": "NUCB",
Expand Down Expand Up @@ -8777,8 +8784,7 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": true,
"upi": true
"nach_debit": true
},
"ORCB": {
"code": "ORCB",
Expand Down Expand Up @@ -10261,7 +10267,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": false,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"SAPX": {
"code": "SAPX",
Expand Down Expand Up @@ -10360,7 +10367,8 @@
"apbs": false,
"ach_credit": true,
"ach_debit": false,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"SBCX": {
"code": "SBCX",
Expand Down Expand Up @@ -10861,7 +10869,8 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": false
"nach_debit": false,
"upi": true
},
"SHKX": {
"code": "SHKX",
Expand Down Expand Up @@ -13329,8 +13338,7 @@
"apbs": true,
"ach_credit": true,
"ach_debit": true,
"nach_debit": true,
"upi": true
"nach_debit": true
},
"UCBA": {
"code": "UCBA",
Expand Down
5 changes: 4 additions & 1 deletion src/node/bank.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ module.exports = Object.freeze({
CMPX: 'CMPX',
CNRB: 'CNRB',
CNSX: 'CNSX',
COAS: 'COAS',
COCX: 'COCX',
COLX: 'COLX',
COMX: 'COMX',
CONX: 'CONX',
CORP: 'CORP',
COAS: 'COAS',
COSB: 'COSB',
CPDX: 'CPDX',
CPSN: 'CPSN',
Expand Down Expand Up @@ -557,6 +557,7 @@ module.exports = Object.freeze({
JSVX: 'JSVX',
JSWX: 'JSWX',
JTIX: 'JTIX',
JTSC: 'JTSC',
JTSX: 'JTSX',
JUCX: 'JUCX',
JUSX: 'JUSX',
Expand Down Expand Up @@ -969,6 +970,7 @@ module.exports = Object.freeze({
RBCX: 'RBCX',
RBIH: 'RBIH',
RBIN: 'RBIN',
RBIP: 'RBIP',
RBIS: 'RBIS',
RCBX: 'RCBX',
RCCX: 'RCCX',
Expand Down Expand Up @@ -1070,6 +1072,7 @@ module.exports = Object.freeze({
SDTC: 'SDTC',
SDTX: 'SDTX',
SDUX: 'SDUX',
SECB: 'SECB',
SEMX: 'SEMX',
SENX: 'SENX',
SEUX: 'SEUX',
Expand Down
Loading

0 comments on commit 2f9e9dc

Please sign in to comment.