Last active
February 3, 2026 19:14
-
-
Save lemajes/4d5e94684e269520201308b5bfc825c9 to your computer and use it in GitHub Desktop.
OVH facture parsing for finops
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # -*- encoding: utf-8 -*- | |
| import ovh | |
| import json | |
| import os | |
| import sys | |
| import argparse | |
| ovh_api_endpoint = os.environ['ovh_api_endpoint'] | |
| ovh_api_application_key = os.environ['ovh_api_application_key'] | |
| ovh_api_application_secret = os.environ['ovh_api_application_secret'] | |
| ovh_api_consumer_key = os.environ['ovh_api_consumer_key'] | |
| client = ovh.Client( | |
| endpoint=ovh_api_endpoint, | |
| application_key=ovh_api_application_key, | |
| application_secret=ovh_api_application_secret, | |
| consumer_key=ovh_api_consumer_key, | |
| ) | |
| def main(args): | |
| params = {} | |
| # params['category'] = {} | |
| params['date.from'] = args.start_date | |
| params['date.to'] = args.end_date | |
| result = client.get("/me/bill", **params) | |
| # print(json.dumps(result, indent=4)) | |
| for item in result: | |
| print(item) | |
| this_bill = client.get(f"/me/bill/{item}/details") | |
| print(json.dumps(this_bill, indent=4)) | |
| for bill in this_bill: | |
| print(f"We're gonna get {bill} details coming from {item}") | |
| this_bill_details = client.get(f"/me/bill/{item}/details/{bill}") | |
| print(json.dumps(this_bill_details, indent=4)) | |
| if __name__ == '__main__': | |
| print("Start: python3 get_invoices.py --start_date 2026-01-01T00:00:00 --end_date 2026-01-31T23:59:59") | |
| parser = argparse.ArgumentParser(description='Fucking OVH bill parser') | |
| parser.add_argument('-s', '--start_date', | |
| help='Start date for billing', | |
| required=True) | |
| parser.add_argument('-e', '--end_date', | |
| help='End date for billing', | |
| required=True) | |
| args = parser.parse_args() | |
| main(args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment