Skip to content

Instantly share code, notes, and snippets.

@Sinkler
Created June 2, 2016 14:39
Show Gist options
  • Save Sinkler/53b437ee8370ac41b0ed16f54ddc60bd to your computer and use it in GitHub Desktop.
Save Sinkler/53b437ee8370ac41b0ed16f54ddc60bd to your computer and use it in GitHub Desktop.
# 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