Last active
December 23, 2016 23:41
-
-
Save maliqq/4961230 to your computer and use it in GitHub Desktop.
текстовая выписка сбербанка -> csv
This file contains hidden or 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
# encoding: utf-8 | |
def parse_date(s) | |
map = {'ЯНВ' => 1, 'ФЕВ' => 2, 'МАР' => 3, 'АПР' => 4, 'МАЙ' => 5, 'ИЮН' => 6, 'ИЮЛ' => 7, 'АВГ' => 8, 'СЕН' => 9, 'ОКТ' => 10, 'НОЯ' => 11, 'ДЕК' => 12} | |
s =~ /^(\d+)(.+?)(\d+)$/ | |
Date.new($3.to_i + 2000, map[$2], $1.to_i) | |
end | |
require 'csv' | |
str = CSV.generate do |csv| | |
while line = gets | |
if line =~ /\s+(\d{2}.{3}) (\d{2}.{3}\d{2}) (\d+) (.+?)\s+(RUR|USD)\s+([\d\.]+)\s+([\d\.]+)(CR)?\s+$/ | |
csv << [parse_date($2), $4, $5, $8 == 'CR' ? $7.to_f : - $7.to_f] | |
end | |
end | |
end | |
print str |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Спасибо!