Example #1
0
    def Calculate(self, monthTransactions):

        self.currentTransactions = monthTransactions
        income = self.sumIncome()
        expenses = self.sumExpenses()
        spending = self.processTransactions()
        remaining = income - expenses - spending["total"]
        forcast = income - expenses - spending["projected"]

        topSpends = self.GetSortedTransactions(max_count=6)
        date = Dates(self.currentTransactions[0]["date"].month,
                     self.currentTransactions[0]["date"].year)

        result = {
            "income": income,
            "spending": spending,
            "topSpends": topSpends,
            "expenses": expenses,
            "forecast": forcast,
            "threshold": self.budgetData["savingsThreshold"],
            "remaining": remaining,
            "date": date
        }

        #if this is a past budget, lets write out the data
        if not date.isCurrentMonthAndYear():
            self.history.Store(spending['total'], remaining, date)
        return result
Example #2
0
    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 get(self):
		userName = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			userName = Employee.checkToken(self.request.cookies.get('our_token'))

		
		template_variables = {}
		
		if userName:
			template_variables['userName'] = userName.userName
			dates =  Dates(template_variables)
			template_variables = dates.nextTwoWeeks()
				
	

			html = template.render("web/templates/ConstrainsInputPage.html", template_variables)
			self.response.write(html)
Example #4
0
    def Run(self, transactions):
        self.SortTransactions(transactions)

        results = []
        if len(self.transactions) == 0:
            return
        if len(self.transactions[0]) == 0:
            return
        earliestDate = Dates(self.transactions[0][0]["date"].month,
                             self.transactions[0][0]["date"].year)
        months = Dates.monthDifference(self.date, earliestDate)

        for index in range(0, len(months)):
            if len(self.transactions) < index + 1:
                trans = [{
                    "date": months[index].getDate(),
                    "amount": 0,
                    "empty": True
                }]
            else:
                trans = self.transactions[index]
            currentDate = months[index]
            if currentDate > self.date:
                break
            val = self.Calculate(trans)
            if self.history.needsPosted(
                    currentDate) or currentDate == self.date:
                results.append(val)

        # for trans in self.transactions:
        #     if (len(trans) == 0):
        #         continue
        #     currentDate = Dates(trans[0]["date"].month, trans[0]["date"].year)
        #     if currentDate > self.date:
        #         break
        #     val = self.Calculate(trans)
        #     if self.history.needsPosted(currentDate) or currentDate == self.date:
        #        results.append(val)
        return results
Example #5
0
cmdLineParser.add_argument("-p",
                           "--port",
                           action="store",
                           type=int,
                           dest="port",
                           default=7497,
                           help="The TCP port to use")
args = cmdLineParser.parse_args()
print("Using args", args)

# IB allows a max of 30 requests / 10 minutes.
# If necessary, we wait for the time here
max_request_per_ten_minutes = 29

# NY Stock Exchange operates between 9:30 AM and 4:00 PM
dates = Dates()
day = '2020-07-18'
initial_date = day + 'T09:33'
final_date = day + 'T16:03'
frequency = '3T'
start_hour = '9:31'
final_hour = '16:00'
dates_list = dates.obtain_dates(initial_date, final_date, frequency,
                                start_hour, final_hour)
print(dates_list)
print(len(dates_list))
# exit()

app = IBapi()
app.connect("127.0.0.1", args.port, 0)
Example #6
0
from Document import Document
from Phones import Phones
from Dates import Dates
from Cep_access import AddressSearch
import requests

cpf = Document.generate_document("01234567890")
print(cpf)

cnpj = Document.generate_document("33969298000100")
print(cnpj)

phone = Phones(554988423605)
print(phone)

date = Dates()
print(date.week_day())
print(date.formated_create_moment)
print(date.create_time())

cep = AddressSearch("89567026")
print(cep)
bairro, cidade, uf = cep.get_via_cep()
print(bairro, cidade, uf)