Created
April 9, 2014 14:45
-
-
Save rennerocha/10278692 to your computer and use it in GitHub Desktop.
conversor cartão itau para moneylog
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
#!/usr/env/python | |
import re | |
import sys | |
def read_credit_card_data(purchases_file, year, tags=None): | |
with open(purchases_file, 'r') as purchases_data: | |
purchases = purchases_data.readlines() | |
moneylog_result = [] | |
for line in purchases: | |
purchase_date, purchase_desc, purchase_value = re.split(r'\t+', line) | |
# Formating date | |
day, month = purchase_date.split('/') | |
purchase_date = '{0}-{1}-{2}'.format(year, month.strip(), day) | |
# Formating value | |
purchase_value = float(purchase_value.replace(',', '.')) | |
# Formating description | |
if tags: | |
purchase_tags = ','.join(tags) | |
purchase_desc = '|'.join([purchase_tags, purchase_desc]) | |
moneylog_line = '{0:<16}{1:<16}{2}'.format(purchase_date, purchase_value, | |
purchase_desc) | |
moneylog_result.append(moneylog_line) | |
return '\n'.join(moneylog_result) | |
if __name__ == '__main__': | |
purchases_file = sys.argv[1] | |
year = sys.argv[2] | |
tags = sys.argv[3:] | |
print purchases_file, year, tags | |
moneylog_result = read_credit_card_data(purchases_file, year, | |
tags) | |
with open('moneylog_result.txt', 'w') as result: | |
result.write(moneylog_result) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment