-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconverter.py
executable file
·38 lines (33 loc) · 1.26 KB
/
converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# coding: utf-8
import csv
import yaml
class Converter(object):
"""
Base class for bank transactions processing
"""
def __init__(self):
with open('public_payees.yml', 'r') as yfile:
self.payees = yaml.load(yfile)
with open('private_payees.yml', 'r') as yfile:
self.payees.update(yaml.load(yfile))
def find_payee(self, *sources):
"""exctract matching payee name from lise of sources"""
for match, payee in self.payees.items():
# first check startswith
if [source for source in sources
if source.lower().startswith(match.lower())]:
return payee
for match, payee in self.payees.items():
# then check contains
if [source for source in sources
if match.lower() in source.lower()]:
return payee
def export_file(self, filename, data):
with open(filename, 'w') as csvfile:
fieldnames = ['Date', 'Payee', 'Category', 'Memo', 'Outflow',
'Inflow']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for row in data:
writer.writerow(row)