Skip to content

Instantly share code, notes, and snippets.

@pobing
Created August 19, 2014 06:49
Show Gist options
  • Save pobing/98cf74905abbd350e285 to your computer and use it in GitHub Desktop.
Save pobing/98cf74905abbd350e285 to your computer and use it in GitHub Desktop.
ruby readline csv file and create new file with sth
require 'csv'
task :token do
require "./config/boot.rb"
res_file = File.new("db/token.txt","w+") # create res file
CSV.foreach("db/token.csv") do |row|
access_token = row.split(';')[0] # get first element
oauth_token = OauthToken.first(:access_token => access_token)
if oauth_token
client_id = oauth_token.client_id
client = Client.first(id: client_id)
res_file.puts("#{client.try(:name)}, #{client_id}, #{access_token}")
end
end
res_file.close
puts "import end :) !"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment