Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
vendor
vendor
public/sitemap*.xml*
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ COPY data /app/data/
RUN echo "** installing deps **" && \
apk --no-cache add redis && \
echo "** installing ruby gems **" && \
gem install bundler && \
echo "** updating bundler **" && \
bundle install && \
echo "** starting redis-server **" && \
redis-server --daemonize yes && \
Expand Down
4 changes: 3 additions & 1 deletion Gemfile.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Gemfile used in the build docker container
source "https://rubygems.org"

gem "redis"
gem "redis"
gem "sitemap_generator"
gem 'to_slug', '~> 1.0', '>= 1.0.8'
10 changes: 8 additions & 2 deletions Gemfile.build.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
GEM
remote: https://rubygems.org/
specs:
redis (4.1.3)
builder (3.2.4)
redis (4.2.5)
sitemap_generator (6.1.2)
builder (~> 3.0)
to_slug (1.0.8)

PLATFORMS
ruby

DEPENDENCIES
redis
sitemap_generator
to_slug (~> 1.0, >= 1.0.8)

BUNDLED WITH
2.0.2
2.2.7
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ DEPENDENCIES
thin

BUNDLED WITH
2.2.6
2.2.7
33 changes: 30 additions & 3 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'ifsc'
require './metrics'
require 'sinatra/json'
require "sinatra/multi_route"
require 'secure_headers'

class IFSCPlus < Razorpay::IFSC::IFSC
Expand Down Expand Up @@ -80,12 +81,19 @@ def ifsc_data(code)
data = settings.redis.hgetall code

if !data.empty?

data['PINCODE'] = nil
data['BANK'], data['BANKCODE'] = bank_details(code)
data['IFSC'] = code
data['RTGS'] = strtobool data['RTGS']
data['NEFT'] = strtobool data['NEFT']
data['IMPS'] = strtobool data['IMPS']
data['UPI'] = strtobool data['UPI']

if data['ADDRESS'] =~ /(\d{6})/
data['PINCODE'] = data['ADDRESS'].match /(\d{6})/
end

settings.metrics.increment code
else
data = nil
Expand All @@ -95,14 +103,33 @@ def ifsc_data(code)
end

get '/' do
readme = File.read 'README.md'
erb :index, locals: { text: markdown(readme) }
erb :index
end

get '/metrics' do
settings.metrics.format
end


get '/:code.html', %r{/[\w-]+/[\w-]+/(?<code>[A-Z0-9]{11})} do
begin
data = ifsc_data(params['code'])
erb :ifsc, locals: { data: data }
rescue StandardError => e
status 404
json 'Not Found'
end
end

get '/banks/:code' do
begin
return json IFSCPlus::Bank.get_details params['code']
rescue Exception => e
status 404
json 'Not Found'
end
end

get '/:code' do
begin
data = ifsc_data(params['code'])
Expand All @@ -115,6 +142,6 @@ def ifsc_data(code)
rescue StandardError => e
puts e
status 404
json 'Not Found'
json "Not Found"
end
end
2 changes: 1 addition & 1 deletion entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/dumb-init /bin/sh
cd /app
redis-server --daemonize yes
bundle exec rackup --host 0.0.0.0 --port 3000
bundle exec rackup --host 0.0.0.0 --port 3000
48 changes: 38 additions & 10 deletions init.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,59 @@
require 'json'
require 'redis'
require 'benchmark'
require 'to_slug'
require 'sitemap_generator'

redis = Redis.new

def log(msg)
puts "[+] (#{Time.now.strftime('%r')}) #{msg}"
end

def add_to_sitemap(sitemap, ifsc, data)
url = nil
if data['BANK'] && data['BRANCH']
url = "/#{data['BANK'].to_s.to_slug}/#{data['BRANCH'].to_s.to_slug}/#{ifsc}"
end
if url
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge both if's

config = { lastmod: Time.now, changefreq: 'monthly', priority: 0.3 }
sitemap.add url, config
end
end

Benchmark.bm(18) do |bm|
bm.report('Ingest:') do
Dir.glob('data/*.json') do |file|
log "Processing #{file}"
bank = File.basename file, '.json'
if Regexp.new('[A-Z]{4}').match(bank)
data = JSON.parse File.read file
data.each do |ifsc, d|
# Remove the extra keys from the JSON files
d.delete_if { |key| %w[BANK IFSC].include? key }
redis.hmset ifsc, *d
# CHANGE TO .com before merging
SitemapGenerator::Sitemap.default_host = 'https://ifsc.stage.razorpay.in'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get it from config may be?

SitemapGenerator::Sitemap.create_index = true

SitemapGenerator::Sitemap.create do |s|
s.add '/', changefreq: 'daily', priority: 0.9
Dir.glob('data/*.json') do |file|
log "Processing #{file}"
bank = File.basename file, '.json'
if Regexp.new('[A-Z]{4}').match(bank)
data = JSON.parse File.read file
data.each do |ifsc, d|
begin
add_to_sitemap(s, ifsc, d)
rescue Exception => e
puts e
end

# Remove the extra keys from the JSON files
d.delete_if { |key| %w[BANK IFSC].include? key }
redis.hmset ifsc, *d
end
log "Processed #{data.size} entries"
end
log "Processed #{data.size} entries"
end
end
end

bm.report('Dump:') do
redis.save
end
end

log('Data saved to Redis')
1 change: 1 addition & 0 deletions public/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sitemap: https://ifsc.stage.razorpay.in/sitemap.xml.gz
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put the prod url. until we submit the sitemap, search engines will not crawl i guess

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool.

66 changes: 66 additions & 0 deletions views/ifsc.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Razorpay IFSC Toolkit</title>
<link href='/main.css' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro' rel='stylesheet' type='text/css'>
<link rel="shortcut icon" href="https://razorpay.com/favicon.png" type="image/png">
</head>
<body class="home-template">
<header class="main-header">
<ul id="nav">
<div class="container">
<li><a id="logo-link" href="https://razorpay.com/?ref=ifsc"></a></li>
<li><a href="https://razorpay.com/blog/">Blog</a></li>
<div class="middle-links">
<li><a href="https://razorpay.com/features/?ref=ifsc">Features</a></li>
<li><a href="https://razorpay.com/demo/?ref=ifsc">Demo</a></li>
<li><a href="https://docs.razorpay.com" target="_blank">Docs</a></li>
</div>
<div class="float-right">
<li><a href="https://dashboard.razorpay.com/#/access/signin" class="login-link">Log In</a></li>
<li><a href="https://dashboard.razorpay.com/#/access/signup?ref=ifsc" class="btn login-link">Sign Up</a></li>
</div>
</div>
</ul>
</header>
<div class='container'>
<table class="ifsc-table">
<tr>
<th>IFSC</th>
<td><%= data['IFSC']%></td>
</tr>
<tr>
<th>Address</th>
<td><%= data['ADDRESS']%></td>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, add https://schema.org/ context schema so that search engines recognize the data easily

</tr>
<tr>
<th>Contact</th>
<td><%= data['CONTACT']%></td>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some of the data is null and it's not sanitized properly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, design is WIP for now.

</tr>
<tr>
<th>City</th>
<td><%= data['CITY']%></td>
</tr>
<tr>
<th>District</th>
<td><%= data['DISTRICT']%></td>
</tr>
<tr>
<th>State</th>
<td><%= data['STATE']%></td>
</tr>
<tr>
<th>RTGS</th>
<td><%= data['RTGS'] ? "Yes" : "No" %></td>
</tr>
<tr>
<th>Bank</th>
<td><%= data['BANK']%> <code>(<%=data['BANKCODE']%>)</code></td>
</tr>
</table>
</div>
</body>
</html>