Created
July 20, 2018 03:18
-
-
Save kp666/895a41a112694a36af97e66b6f8f1a24 to your computer and use it in GitHub Desktop.
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
class Country < ActiveRecord::Base | |
end | |
file='news.txt' | |
def find_country_code(line) | |
line[/\(\S*\)/,0].to_s.gsub(/[()]/, "") | |
end | |
def find_country(country_code) | |
Country.where(country_code: country_code).last | |
end | |
CSV.open("reworked.csv", "w") do |f| | |
File.readlines(file).each do |line| | |
country_code = find_country_code(line) | |
country = find_country(country_code).country rescue "unknown" | |
f << [country] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment