Created
December 10, 2023 23:04
-
-
Save needcaffeine/3577a83ef45d88d8eeffdbe93886aaed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# given a bunch of folders which are years, and contents which are files of the form YYYY-mm-dd - name - $1234.56, | |
# this script returns a sum of totals by year | |
import os | |
totals = {} | |
for year in os.listdir('.'): | |
if os.path.isdir(year) and not year.startswith('.'): | |
total = 0 | |
for file in os.listdir(year): | |
if file[0] != '.' and file != 'Reimbursed': | |
parts = file.split(' - ') | |
if len(parts) > 2: | |
amount = parts[2].rsplit('.', 1)[0] # Split from the right to keep decimal part | |
amount = amount.replace('$', '') # Remove dollar sign | |
total += float(amount) | |
totals[year] = total | |
# Sort the years and print the totals | |
for year in sorted(totals): | |
print(f'{year} {totals[year]:.2f}') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment