Skip to content

Instantly share code, notes, and snippets.

@maliqq
Last active December 23, 2016 23:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save maliqq/4961230 to your computer and use it in GitHub Desktop.
Save maliqq/4961230 to your computer and use it in GitHub Desktop.
текстовая выписка сбербанка -> csv
# 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
@fshp
Copy link

fshp commented Dec 23, 2016

Спасибо!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment