Created
December 27, 2023 22:11
-
-
Save MickaelBergem/97a549eb8b7fe4380d724498518b1bd5 to your computer and use it in GitHub Desktop.
Generate a calendar with all future payments from Enerfip (crowdfunding for renewable energy projects)
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
""" | |
Go to https://fr.enerfip.eu/app/accounts/, click "Mon échéancier", then at the bottom of the page click "Exporter au format XLS". | |
""" | |
import os | |
from datetime import datetime | |
import xlrd | |
from ics import Calendar, Event | |
path_to_downloaded_xls_file = os.path.expanduser('~') + '/Downloads/transactions.xls' | |
target_calendar_file = os.path.expanduser('~') + '/Downloads/enerfip.ics' | |
book = xlrd.open_workbook(path_to_downloaded_xls_file) | |
print(f"Using sheet named {book.sheet_names()[0]}...") | |
sheet = book.sheet_by_index(0) | |
header = sheet.row(0) | |
print(header) | |
calendar = Calendar() | |
for rx in range(1, sheet.nrows): | |
payment_date, project_name, paid_amount, reimbursed_capital, paid_interests, remaining_capital = sheet.row(rx) | |
event_date = datetime.strptime(payment_date.value, '%d/%m/%Y').date() | |
print(event_date, project_name.value, paid_amount.value, reimbursed_capital, paid_interests, remaining_capital) | |
event = Event( | |
name=f"Paiement Enerfip de {paid_amount.value}€ ({project_name.value})", | |
description=f"Remboursement de capital : {reimbursed_capital.value}€\nIntérêts payés : {paid_interests.value}€\nCapital restant dû : {remaining_capital.value}€", | |
begin=event_date, | |
) | |
event.make_all_day() | |
calendar.events.add(event) | |
with open(target_calendar_file, 'w') as f: | |
f.writelines(calendar.serialize_iter()) | |
print(f"\n✨ Success: {target_calendar_file} has been generated.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment