import csv
from csv import DictReader

def statement(filename):
	with open(filename, 'r') as statementFile:
		# remove beginning and trailing spaces in the headers
		headers = [header.strip() for header in statementFile.readline().split(',')]
		statement = DictReader(statementFile, fieldnames = headers)
		# lazily read the file
		for entry in statement:
			if(entry):
				yield entry
food_family = ['waitrose', 'lidl', 'tesco']
food_sky = ['sky restaurant']
travel = ['tfl.gov.uk', 'avis']
mobile = ['giffgaff']

spending_food_family= 0.0
spending_food_sky = 0.0
spending_travel = 0.0
spending_mobile = 0.0

def is_spending_category(transaction_desc, category_vendors):
	for vendor in category_vendors:
		if vendor in transaction_desc.lower():
			return True

	return False

for transaction in statement('statement.csv'):
	# print(transaction['Date'], transaction['Description'], transaction['Value'])
	if is_spending_category(transaction['Description'], food_family):
		spending_food_family += float(transaction['Value'])

print 'Spending on Food: %s' % str(0 - spending_food_family)

