Last active
March 13, 2017 17:39
-
-
Save ldodds/95b6b8f9491ed5c7e29fe6fb9ae55221 to your computer and use it in GitHub Desktop.
Dump open banking ATM data to CSV
This file contains hidden or 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
| require 'csv' | |
| require 'json' | |
| require 'rest-client' | |
| #Hack to work around SSL error received from Bank of Ireland and Nationwide end points | |
| #SSL_connect returned=1 errno=0 state=error: certificate verify failed | |
| def get_no_ssl(url, headers={}, &block) | |
| RestClient::Request.execute(method: :get, url: url, headers: headers, verify_ssl: false, &block) | |
| end | |
| #Certificate errors on two, need an updated SSL root cert? | |
| URLS = [ | |
| "https://openapi.bankofireland.com/open-banking/v1.2/atms", | |
| "https://atlas.api.barclays/open-banking/v1.3/atms", | |
| "https://obp-api.danskebank.com/open-banking/v1.2/atms", | |
| "https://openapi.nationwide.co.uk/open-banking/v1.2/atms", | |
| "https://openapi.natwest.com/open-banking/v1.2/atms", | |
| "https://openapi.rbs.co.uk/open-banking/v1.2/atms", | |
| "https://api.santander.co.uk/retail/open-banking/v1.2/atms", | |
| "https://openapi.ulsterbank.co.uk/open-banking/v1.2/atms" | |
| ] | |
| CSV.open("atms.csv", "w:UTF-8") do |csv| | |
| csv << ["ATMID", "SiteName", "BuildingNumberOrName", "Country", "PostCode", "StreetName", "TownName", "Currency", "Services", "LocationCategory","MinimumValueDispensed", "Organisation", "SupportedLanguages", "Latitude", "Longitude"] | |
| URLS.each do |url| | |
| puts url | |
| resp = JSON.parse( get_no_ssl(url) ) | |
| resp["data"].each do |atm| | |
| currency = atm["Currency"].join("|") if atm["Currency"] | |
| services = atm["Services"].join("|") if atm["Services"] | |
| csv << [ atm["ATMID"], | |
| atm["SiteName"], | |
| atm["Address"]["BuildingNumberOrName"], | |
| atm["Address"]["Country"], | |
| atm["Address"]["PostCode"], | |
| atm["Address"]["StreetName"], | |
| atm["Address"]["TownName"], | |
| currency, | |
| services, | |
| atm["LocationCategory"], | |
| atm["MinimumValueDispensed"], | |
| atm["Organisation"]["ParentOrganisation"]["OrganisationName"]["LegalName"], | |
| atm["SupportedLanguages"].join("|"), | |
| atm["GeographicLocation"]["Latitude"], | |
| atm["GeographicLocation"]["Longitude"] ] | |
| end | |
| end | |
| end | |
This file contains hidden or 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
| source 'https://rubygems.org' | |
| gem 'rest-client' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment