Ejemplo n.º 1
0
#!/usr/bin/python

import sys
import csv
import rules
import calendar
from datetime import datetime

try:
	f = open(rules.getPath()+'expenses.csv','a')
	writer = csv.writer(f)

	if (datetime.now().year != 2015):
		raise Exception("Update rental cost for the new year.")

	desc = sys.argv[1]
	month = int(sys.argv[2])

	if (desc == 'Rent'):
		date = str(month)+"/01/2015"
		cost = 1243.38
	elif (desc == 'PGE' or desc == 'EBMUD'):
		date = str(month)+"/"+str(calendar.monthrange(datetime.now().year,month)[1])+"/"+str(datetime.now().year)
		cost = float(sys.argv[3])
	else:
		raise Exception("Invalid manual option.")

	rule = rules.applyRules(date,desc,cost,'none')
	if rule == 'none':
		print "Modify rules manually."
		sys.exit(1)
Ejemplo n.º 2
0
    tempFile.write("\tif '" + desc + "' in desc:\n")
    tempFile.write("\t\treturn Rules." + rule + "\n")
    tempFile.write("\treturn 'none'\n")

    # close and replace file
    ruleFile.close()
    tempFile.close()
    subprocess.call("mv rules.temp rules.py", shell=True)

    # reload the rules module because it has changed
    reload(rules)

    return rule


log = open(rules.getPath() + "expenses.csv", "a")
writer = csv.writer(log)
chkban = ["Express", "Chase", "VGI", "FID"]
cardban = ["Amazon.com", "AMAZON MKT"]

csvlist = subprocess.check_output("ls " + rules.getPath(), shell=True).split("\n")
csvlist.remove("archive")
csvlist.remove("expenses.csv")
csvlist.remove("")

for item in csvlist:
    try:
        f = open(rules.getPath() + item)
        reader = csv.reader(f)
    except:
        print "not a valid CSV file"