def parseTransferedDividendData(name, AsDate=False, AsFloat=False): date_d, amount_d = [], [] if files_encrypted: #decrypting... try: with open("csv/" + name + "/" + name + "_div_trans.csv", "rb") as file: data = file.read() # print("csv/"+name+"/"+name+"_div_trans.csv","is being decrypted...") decrypted = encryption.getFernet(encryption_salt).decrypt( data).decode() for rows in decrypted.split("\n")[1:]: Date = rows.split(";")[0] if Date == "": break #end of file amount = rows.split(";")[1] if AsDate: date_d.append( str( date(int(Date[-4:]), int(Date[3:5]), int(Date[:2])))) else: date_d.append( str(Date[:2]) + "." + str(Date[3:5]) + "." + str(Date[-4:])) #y,m,d if AsFloat: amount_d.append(ConvertToFloat(str(amount))) else: amount_d.append(str(amount)) except FileNotFoundError: date_d, amount_d = [], [] else: '''previous parser using .csv parsers''' try: with open("csv/" + name + "/" + name + "_div_trans.csv") as csvfile: reader = csv.DictReader(csvfile, delimiter=";") for row in reader: if AsDate: date_d.append( str( date(int(row['Date'][-4:]), int(row['Date'][3:5]), int(row['Date'][:2])))) else: date_d.append( str(row['Date'][:2]) + "." + str(row['Date'][3:5]) + "." + str(row['Date'][-4:])) #y,m,d if AsFloat: amount_d.append(ConvertToFloat(str(row['Amount']))) else: amount_d.append(str(row['Amount'])) except FileNotFoundError: date_d, amount_d = [], [] return date_d, amount_d
def parseLiqudityData(name, AsDate=False, AsFloat=False): date_b, amount_b = [], [] if files_encrypted: #decrypting... with open("csv/" + name + "/" + name + ".csv", "rb") as file: data = file.read() # print("csv/"+name+"/"+name+".csv","is being decrypted...") decrypted = encryption.getFernet(encryption_salt).decrypt( data).decode() for rows in decrypted.split("\n")[1:]: #ignoring the headline Date = rows.split(";")[0] if Date == "": break #end of file amount = rows.split(";")[1] if AsDate: date_b.append( str(date(int(Date[-4:]), int(Date[3:5]), int(Date[:2])))) else: date_b.append( str(Date[:2]) + "." + str(Date[3:5]) + "." + str(Date[-4:])) #y,m,d if AsFloat: amount_b.append(ConvertToFloat(str(amount))) else: amount_b.append(str(amount)) else: '''previous parser using .csv parsers''' with open("csv/" + name + "/" + name + ".csv") as csvfile: reader = csv.DictReader(csvfile, delimiter=";") for row in reader: if AsDate: date_b.append( str( date(int(row['Date'][-4:]), int(row['Date'][3:5]), int(row['Date'][:2])))) else: date_b.append( str(row['Date'][:2]) + "." + str(row['Date'][3:5]) + "." + str(row['Date'][-4:])) #y,m,d if AsFloat: amount_b.append(ConvertToFloat(str(row['Amount']))) else: amount_b.append(str(row['Amount'])) return date_b, amount_b
def writeNewCSVData(i, name, new_date_b, new_amount_b): if files_encrypted: with open("csv/" + name + "/" + name + "_inv.csv", 'rb') as f: data = f.read() f = encryption.getFernet(encryption_salt) decrypted = f.decrypt(data).decode() newcontent = "Date;Amount\n" for j in range(len(new_date_b)): newcontent += ConvertDateToGerman( new_date_b[j]) + ";" + new_amount_b[j] + "\n" encrypted = f.encrypt(bytes(newcontent.encode())) with open("csv/" + name + "/" + name + "_inv.csv", 'wb') as file: file.write(encrypted) else: '''previous CSV Writer''' with open("csv/" + name + "/" + name + "_inv.csv", mode='w') as csvfile: writer = csv.writer(csvfile, delimiter=";") writer.writerow(["Date", "Amount", ""]) for j in range(len(new_date_b)): writer.writerow( [ConvertDateToGerman(new_date_b[j]), new_amount_b[j]])
def parseInvestementData(i, name, AsDate=False): checkMonthlyAutomatisation(i, name) date_b, amount_b, date_d, amount_d = [], [], [], [] if files_encrypted: #decrypting... with open("csv/" + name + "/" + name + "_inv.csv", "rb") as file: data = file.read() # print("csv/"+name+"/"+name+"_inv.csv","is being decrypted...") decrypted = encryption.getFernet(encryption_salt).decrypt(data) decrypted = decrypted.decode() for rows in decrypted.split("\n")[1:]: #ignoring the headline Date = rows.split(";")[0] if Date == "": break #end of file amount = rows.split(";")[1] if AsDate: date_b.append( str(date(int(Date[-4:]), int(Date[3:5]), int(Date[:2])))) else: date_b.append( str(Date[:2]) + "." + str(Date[3:5]) + "." + str(Date[-4:])) #y,m,d amount_b.append(str(amount)) with open("csv/" + name + "/" + name + "_div.csv", "rb") as file: data = file.read() # print("csv/"+name+"/"+name+"_div.csv","is being decrypted...") decrypted = encryption.getFernet(encryption_salt).decrypt(data) decrypted = decrypted.decode() for rows in decrypted.split("\n")[1:]: Date = rows.split(";")[0] if Date == "": break #end of file amount = rows.split(";")[1] if AsDate: date_d.append( str(date(int(Date[-4:]), int(Date[3:5]), int(Date[:2])))) else: date_d.append( str(Date[:2]) + "." + str(Date[3:5]) + "." + str(Date[-4:])) #y,m,d amount_d.append(str(amount)) else: '''previous parser using .csv parsers''' with open("csv/" + name + "/" + name + "_inv.csv") as csvfile: reader = csv.DictReader(csvfile, delimiter=";") for row in reader: if AsDate: date_b.append( str( date(int(row['Date'][-4:]), int(row['Date'][3:5]), int(row['Date'][:2])))) else: date_b.append( str(row['Date'][:2]) + "." + str(row['Date'][3:5]) + "." + str(row['Date'][-4:])) #y,m,d amount_b.append(str(row['Amount'])) with open("csv/" + name + "/" + name + "_div.csv") as csvfile: reader = csv.DictReader(csvfile, delimiter=";") for row in reader: if AsDate: date_d.append( str( date(int(row['Date'][-4:]), int(row['Date'][3:5]), int(row['Date'][:2])))) else: date_d.append( str(row['Date'][:2]) + "." + str(row['Date'][3:5]) + "." + str(row['Date'][-4:])) #y,m,d amount_d.append(str(row['Amount'])) return date_b, amount_b, date_d, amount_d
def checkMonthlyAutomatisation(i, name): deka_date = [] deka_price = [] filename = "csv/" + name + "/" + name + ".csv" with open(filename) as csvfile: reader = csv.DictReader(csvfile, delimiter=";") for row in reader: deka_date.append( date(int(row['Datum'][-4:]), int(row['Datum'][3:5]), int(row['Datum'][:2]))) deka_price.append(ConvertToFloat(row['Ausgabepreis'])) date_b, amount_b = [], [] if files_encrypted: #decrypting... with open("csv/" + name + "/" + name + "_inv.csv", "rb") as file: data = file.read() # print("csv/"+name+"/"+name+"_inv.csv","is being decrypted...") decrypted = encryption.getFernet(encryption_salt).decrypt( data).decode() for rows in decrypted.split("\n")[1:]: #ignoring the headline Date = rows.split(";")[0] if Date == "": break #end of file amount = rows.split(";")[1] date_b.append( date(int(Date[-4:]), int(Date[3:5]), int(Date[:2]))) amount_b.append(str(amount)) else: '''previous decryptor...''' with open("csv/" + name + "/" + name + "_inv.csv") as csvfile: reader = csv.DictReader(csvfile, delimiter=";") for row in reader: date_b.append( date(int(row['Date'][-4:]), int(row['Date'][3:5]), int(row['Date'][:2]))) amount_b.append(str(row['Amount'])) monthly_autom = config[i]["aut"] if monthly_autom != "": monthly_d_0 = date(int(monthly_autom[-4:]), int(monthly_autom[3:5]), int(monthly_autom[:2])) monthly_d_ref = monthly_d_0 j = 0 k = 0 while (monthly_d_ref - datetime.date.today()).days <= 0: datebuy = date_b[0] for d in deka_date: timedelta = d - monthly_d_ref if timedelta.days >= 0: datebuy = d break if datebuy not in date_b: x, y1, y2 = parseDekaData(i, name) info.append( str("\033[30;44mInfo:\033[0m Invested " + config[i]["aut_amount"] + " in " + name + " on " + str(datebuy) + " for " + str(y2[int(x.index(str(datebuy)))]))) date_b = [datebuy] + date_b amount_b = [str(config[i]["aut_amount"])] + amount_b writeNewCSVData(i, name, date_b, amount_b) j += 1 if (int(monthly_autom[3:5]) + j) % 12 == 1: k += 1 if (int(monthly_autom[3:5]) + j) % 12 == 0: monthly_d_ref = date( int(monthly_autom[-4:]) + k, 12, int(monthly_autom[:2])) else: monthly_d_ref = date( int(monthly_autom[-4:]) + k, (int(monthly_autom[3:5]) + j) % 12, int(monthly_autom[:2]))