forked from willderness/python-collections-budget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Expense.py
42 lines (36 loc) · 1.55 KB
/
Expense.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
39
40
41
42
import csv
from datetime import datetime
class Expense():
def __init__(self, date_str, vendor, category, amount):
self.date_time = datetime.strptime(date_str, '%m/%d/%Y %H:%M:%S')
self.vendor = vendor
self.category = category
self.amount = amount
class Expenses():
def __init__(self):
self.list = []
self.sum = 0
# Read in the December spending data, row[2] is the $$, and need to format $$
def read_expenses(self,filename):
with open(filename, newline='') as csvfile:
csvreader = csv.reader(csvfile, delimiter=',')
for row in csvreader:
if '-' not in row[3]:
continue
amount = float((row[3][2:]).replace(',',''))
self.list.append(Expense(row[0],row[1], row[2], amount))
self.sum += amount
def categorize_for_loop(self):
necessary_expenses = set()
food_expenses = set()
unnecessary_expenses = set()
for i in self.list:
if (i.category == 'Phone' or i.category == 'Auto and Gas' or
i.category == 'Classes' or i.category == 'Utilities' or
i.category == 'Mortgage'):
necessary_expenses.add(i)
elif(i.category == 'Groceries' or i.category == 'Eating Out'):
food_expenses.add(i)
else:
unnecessary_expenses.add(i)
return [necessary_expenses, food_expenses, unnecessary_expenses]