def __init__(self, output=None, date=Dates.empty()): self.date = date self.budgetData = Configuration().getBudget() self.transactions = [] self.outputFile = output self.outFileCount = 0 self.history = History()
def Run(self, start=0, end=-1, browser=False, date=Dates.empty(), lookBack=1): self.userDate = date self.beginDate = Dates.previousMonth(self.userDate, lookBack) if browser: try: self.UI.OpenBrowser(Configuration().getBrowserTitle(), Configuration().getBrowserPath()) except Exception as e: raise Exception("OpenBrowser: " + str(e)) if end == -1: end = len(self.processMap) else: self.shouldClose = False for i in range(start, end): func, error = self.processMap[i] try: func() except Exception as e: raise Exception(error + ": " + str(e)) if not self.shouldClose: return if browser: try: self.UI.CloseBrowser() except Exception as e: raise Exception("CloseBrowser: " + str(e))
def Run(self, simulate=False, date=Dates.empty(), lookBack=1): os.makedirs(os.getcwd()+'\\'+ self.name, exist_ok=True) if self.bankWeb == None or self.bankParser == None: raise Exception("Bank or parser not defined") if not simulate: self.bankWeb.Run(date=date, lookBack=lookBack) self.bankParser.Run(date=date)
def Run(self, date=Dates.empty()): self.userDate = date try: self.transactions = self.processHTML() if self.transactions == None: raise except Exception as e: raise Exception("Could not read HTML data: " + str(e))
def firstTime(self, **kwargs): with open('Config\\configuration.json', mode='r') as f: jData = f.read() self.data = json.loads(jData) if "settings" not in self.data: self.addSettings({ "lookBackMonths": 1, "currentDate": Dates.empty() }) else: if "lookBackMonths" not in self.data["settings"]: self.addSettings({"lookBackMonths": 1}) if "currentDate" not in self.data["settings"]: self.addSettings({"currentDate": Dates.empty()}) else: date = Dates.string(self.data["settings"]["currentDate"]) self.addSettings({"currentDate": date})
def Run(self, simulate=False, date=Dates.empty(), lookBack=1): if not simulate: GUI().OpenBrowser(Configuration().getBrowserTitle(), Configuration().getBrowserPath()) for bank in self.banks: bank.Run(simulate=simulate, date=date, lookBack=lookBack) self.transactions.extend(bank.GetTransactions()) if not simulate: GUI().CloseBrowser()
def processTransactions(self): total = 0 if self.outputFile != None: base = os.path.splitext(self.outputFile)[0] base = base + '-' + str(self.outFileCount) + os.path.splitext( self.outputFile)[1] self.outFileCount += 1 f = open(base, mode="w") t = sorted(self.currentTransactions, key=lambda x: x["amount"]) else: t = self.currentTransactions for trans in t: if "empty" in trans: continue if self.outputFile != None: f.write('"{}", {}\n'.format(trans["description"], trans["amount"])) if not self.ignored(trans["description"]): total += trans["amount"] if self.outputFile != None: f.close() #is this month over? now = Dates.empty() then = self.currentTransactions[0]["date"] oldDate = Dates(then.month, then.year) days = oldDate.pastDays() + oldDate.remainingDays() if (now > Dates(then.month, then.year)): average = total / days projection = total else: #we are working with an incomplete month, use history average = total / self.date.pastDays() dailyProjection = self.history.calculateWeightedAverage( average, self.date) projection = dailyProjection * self.date.remainingDays() + total result = { "total": total, "dailyAverage": average, "projected": projection } return result
def tick(self, simulate=False, date=Dates.empty(), lookBack=Configuration().getSettings()["lookBackMonths"]): print("Doing tick") processor = TransactionProcessor() try: processor.Run(simulate=simulate, date=date, lookBack=lookBack) except: self.errorLog.append( "----------------------------------------------------") self.errorLog.extend(traceback.format_exc().splitlines()) self.errorLog.append( "----------------------------------------------------") for l in self.errorLog: print(l) return False budget = Budget(date=date, output="C:\\tmp\\trans.csv") results = budget.Run(processor.GetTransactions()) Email().Run(results) return True
def Run(self, data, date=Dates.empty()): self.date = date for item in data: self.processMonth(item) self.history.writeData()
def isValid(self, dateStr): if Dates.string(dateStr) > Dates.empty(): return False return True