require 'digest/sha1' ENV['RAILS_ENV'] = "production" APILog = Logger.new("#{RAILS_ROOT}/log/API_#{RAILS_ENV}.log") namespace :api do desc "Update Wallet and incoming payments" task (:update => :environment) do api = Recache::API.new('api userid', 'api key') wallet = api.personal_wallet_journal({:characterid=>1238308359}) if api.last_call_updated then wallet.each do |entry| hash = Digest::SHA1.hexdigest("--#{entry.ref_id}--#{entry.amount}--#{entry.owner_id1}--#{entry.date}") if not Transaction.exists?(:eve_transaction_hash => hash) c = Character.find_by_eve_id(entry.owner_id1) if c Transaction.create!( :sender_id => 0, :recipient_id => c.user_id, :amount => entry.amount.to_i, :remark => "Transfer at #{entry.date}", :transaction_reason_id => 4, :eve_transaction_hash => hash ) else APILog.info "Failed to add to account- character not found for transfer of #{entry.amount} at #{entry.date} from #{entry.owner_name1}." end end end end end end