Created
August 19, 2014 06:49
-
-
Save pobing/98cf74905abbd350e285 to your computer and use it in GitHub Desktop.
ruby readline csv file and create new file with sth
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 '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