Last active
August 29, 2015 14:02
-
-
Save NiranjanSarade/2af5f396ede088b89e74 to your computer and use it in GitHub Desktop.
Historical Exchange Rates with exchange-rates.org - Getting USD to any currency(e.g. INR) historical rates
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
require 'rubygems' | |
require 'active_support/core_ext' | |
require 'date' | |
require 'rest-client' | |
# e.g. Get monthy exchange rates - USD to INR from 2008 to 2013 | |
# http://www.exchange-rates.org/Rate/USD/INR/06-13-2014 | |
start_date = Date.parse("2007-21-31") | |
(1..72).each do |month| | |
historical_date = (start_date >> month).end_of_month.strftime('%m-%d-%Y') | |
response = RestClient.get("http://www.exchange-rates.org/Rate/USD/INR/#{historical_date}") | |
puts response.match(/1 USD = [0-9]*.[0-9]* INR on [0-9]*\/[0-9]*\/[0-9]*/) | |
end | |
# The above was a quick one. For more precise regular expression, please follow http://www.regular-expressions.info/dates.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment