mirror of
https://github.com/hakanensari/frankfurter.git
synced 2024-11-25 04:22:28 +01:00
Work around ecb rate limiting
This commit is contained in:
parent
706e084eb2
commit
cb51bca58b
@ -5,7 +5,7 @@ require 'rufus-scheduler'
|
||||
|
||||
scheduler = Rufus::Scheduler.new
|
||||
|
||||
scheduler.cron '*/15 15,16,17 * * 1-5' do
|
||||
scheduler.cron '*/30 15,16,17 * * 1-5' do
|
||||
`rake rates:current`
|
||||
end
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
`rake db:setup`
|
||||
`rake db:prepare`
|
||||
|
||||
worker_process_count = (ENV['WORKER_PROCESSES'] || 4).to_i
|
||||
|
||||
|
@ -30,6 +30,13 @@ module Bank
|
||||
Day.multi_insert(data)
|
||||
end
|
||||
|
||||
def seed_with_saved_data!
|
||||
data = Feed.saved_data.to_a
|
||||
jsonify!(data)
|
||||
Day.dataset.delete
|
||||
Day.multi_insert(data)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def jsonify!(data)
|
||||
|
1
lib/bank/eurofxref-hist.xml
Normal file
1
lib/bank/eurofxref-hist.xml
Normal file
File diff suppressed because one or more lines are too long
@ -8,42 +8,42 @@ module Bank
|
||||
include Enumerable
|
||||
|
||||
def self.current
|
||||
new('daily')
|
||||
url = URI('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml')
|
||||
xml = Net::HTTP.get(url)
|
||||
|
||||
new(xml)
|
||||
end
|
||||
|
||||
def self.ninety_days
|
||||
new('hist-90d')
|
||||
url = URI('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml')
|
||||
xml = Net::HTTP.get(url)
|
||||
|
||||
new(xml)
|
||||
end
|
||||
|
||||
def self.historical
|
||||
new('hist')
|
||||
url = URI('https://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist.xml')
|
||||
xml = Net::HTTP.get(url)
|
||||
|
||||
new(xml)
|
||||
end
|
||||
|
||||
def initialize(scope)
|
||||
@scope = scope
|
||||
def self.saved_data
|
||||
xml = File.read(File.join(__dir__, 'eurofxref-hist.xml'))
|
||||
new(xml)
|
||||
end
|
||||
|
||||
def initialize(xml)
|
||||
@document = Ox.load(xml)
|
||||
end
|
||||
|
||||
def each
|
||||
document.locate('gesmes:Envelope/Cube/Cube').each do |day|
|
||||
@document.locate('gesmes:Envelope/Cube/Cube').each do |day|
|
||||
yield(date: Date.parse(day['time']),
|
||||
rates: day.nodes.each_with_object({}) do |currency, rates|
|
||||
rates[currency[:currency]] = Float(currency[:rate])
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def document
|
||||
Ox.load(xml)
|
||||
end
|
||||
|
||||
def xml
|
||||
Net::HTTP.get(url)
|
||||
end
|
||||
|
||||
def url
|
||||
URI("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-#{@scope}.xml")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -12,5 +12,13 @@ namespace :db do
|
||||
Sequel::IntegerMigrator.new(db, dir, opts).run
|
||||
end
|
||||
|
||||
task setup: %w[db:migrate rates:all]
|
||||
task prepare: %w[db:migrate rates:all]
|
||||
|
||||
namespace :test do
|
||||
task :prepare do
|
||||
ENV['APP_ENV'] ||= 'test'
|
||||
Rake::Task['db:migrate'].invoke
|
||||
Rake::Task['rates:seed_with_saved_data'].invoke
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -18,4 +18,9 @@ namespace :rates do
|
||||
require 'bank'
|
||||
Bank.fetch_current!
|
||||
end
|
||||
|
||||
task :seed_with_saved_data do
|
||||
require 'bank'
|
||||
Bank.seed_with_saved_data!
|
||||
end
|
||||
end
|
||||
|
@ -15,4 +15,4 @@ end
|
||||
|
||||
RuboCop::RakeTask.new
|
||||
|
||||
task default: %w[db:setup test rubocop]
|
||||
task default: %w[db:test:prepare test rubocop]
|
||||
|
Loading…
Reference in New Issue
Block a user