Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created March 30, 2020 04:17
Show Gist options
  • Save amarinelli/384563f15dc0471c9c3f92ab428abac4 to your computer and use it in GitHub Desktop.
Save amarinelli/384563f15dc0471c9c3f92ab428abac4 to your computer and use it in GitHub Desktop.
with open("import.txt") as file:
data = file.read()
lines = data.split("\n")
with open("export.csv", "w") as output:
output.write("date, amount, desc\n")
year = "19"
balance = 8698.05
for line in lines:
first_split = line.split(" " + year, 1)
date = first_split[0].strip() + " " + year
sec_split = first_split[1].split("$")
desc = sec_split[0].strip().replace(",", " ")
line_balance = float(sec_split[2].strip().replace(",", ""))
if line_balance > balance:
amount = "$" + sec_split[1].strip().replace(",", "")
else:
amount = "-$" + sec_split[1].strip().replace(",", "")
# print(balance, amount, line_balance)
balance = line_balance
output.write("{0}, {1}, {2}\n".format(date, amount, desc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment