Created
June 2, 2016 14:39
-
-
Save Sinkler/53b437ee8370ac41b0ed16f54ddc60bd 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
# coding=utf-8 | |
# from cashculator export to debit & credit import | |
import csv | |
file_name = 'out.csv' | |
def convert_date(date): | |
data = { | |
u'янв.-': '01.01.', | |
u'февр.-': '01.02.', | |
u'март-': '01.03.', | |
u'апр.-': '01.04.', | |
u'май-': '01.05.', | |
u'июнь-': '01.06.', | |
u'июль-': '01.07.', | |
u'авг.-': '01.08.', | |
u'сент.-': '01.09.', | |
u'окт.-': '01.10.', | |
u'нояб.-': '01.11.', | |
u'дек.-': '01.12.', | |
} | |
date = date.decode('utf-8') | |
for d in data: | |
date = date.replace(d, data[d]) | |
return date | |
with open(file_name) as csv_file: | |
output = [] | |
dates = [] | |
for i, r in enumerate(csv.reader(csv_file, delimiter=',')): | |
if not i: | |
dates = r[1:] | |
else: | |
category = r[0] | |
for j, c in enumerate(r[1:]): | |
if not float(c): | |
continue | |
output.append([category, convert_date(dates[j]), c]) | |
with open('out_' + file_name, 'wb') as csv_file: | |
writer = csv.writer(csv_file) | |
for r in output: | |
writer.writerow(r) | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment