diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bedd829..bb6e00f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,7 @@ def best_deals lowest = games.flat_map(&:prices).min_by { |price| price.value.exchange_to('USD') } next if lowest.blank? rates = currencies.map { |c| lowest.value.exchange_to(c).format } - rows << [game.first.title, ISO3166::Country[lowest.country].translation('en')].concat(rates) + rows << [games.first.title, ISO3166::Country[lowest.country].translation('en')].concat(rates) end end @@ -45,6 +45,24 @@ def glossary send_data csv, type: 'text/csv; charset=utf-8; header=present' end + def rates + currencies = Price.distinct.pluck(:currency).sort + + csv = CSV.generate(headers: true) do |rows| + rows << [''].concat(currencies) + + currencies.each do |from| + row = [from] + currencies.each do |to| + row << Money.default_bank.get_rate(from, to) + end + rows << row + end + end + + send_data csv, type: 'text/csv; charset=utf-8; header=present' + end + def about csv = CSV.generate(headers: true) do |rows| rows << ['Page url', 'http://eshop.calyh.re'] diff --git a/lib/tasks/eshop.rake b/lib/tasks/eshop.rake index e04e8dd..ca58c50 100644 --- a/lib/tasks/eshop.rake +++ b/lib/tasks/eshop.rake @@ -29,7 +29,7 @@ namespace :eshop do desc 'Detect new shops that were not selling games before' task detect_new_shops: :environment do - ids = Game.distinct.pluck(:nsuid).compact.sample(50) + ids = Game.distinct.pluck(:nsuid).compact new_shops = [] puts "Retrieving #{ids.count} prices..." countries = Eshop::REGIONS.values.flatten.uniq.sort - Eshop::COUNTRIES