Files
2026-04-12 22:37:35 +02:00

58 lines
2.0 KiB
Python

#!/usr/bin/env python3
import argparse
import logging
import sys
from config import Config
from downloader import download_all_invoices
def main():
parser = argparse.ArgumentParser(description="Download Backblaze invoices as PDF")
parser.add_argument("--output", "-o", help="Output directory", default=None)
parser.add_argument("--headless", action="store_true", default=None, help="Run browser headless")
parser.add_argument("--no-headless", action="store_true", default=False, help="Show browser window")
parser.add_argument("--vat-id", help="VAT ID to fill on invoices")
parser.add_argument("--document-type", help="Document type to select")
parser.add_argument("--company", help="Company name to fill")
parser.add_argument("--notes", help="Notes to fill on invoices")
parser.add_argument("--all-years", action="store_true", help="Download invoices for all years")
parser.add_argument("--verbose", "-v", action="store_true", help="Verbose logging")
args = parser.parse_args()
logging.basicConfig(
level=logging.DEBUG if args.verbose else getattr(logging, Config.LOG_LEVEL),
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
datefmt="%H:%M:%S",
)
if args.output:
Config.OUTPUT_DIR = args.output
if args.no_headless:
Config.BROWSER_HEADLESS = False
elif args.headless is True:
Config.BROWSER_HEADLESS = True
if args.vat_id:
Config.INVOICE_VAT_ID = args.vat_id
if args.document_type:
Config.INVOICE_DOCUMENT_TYPE = args.document_type
if args.company:
Config.INVOICE_COMPANY = args.company
if args.notes:
Config.INVOICE_NOTES = args.notes
if args.all_years:
Config.DOWNLOAD_ALL_YEARS = True
try:
Config.validate()
except ValueError as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)
saved = download_all_invoices()
print(f"\nDone. {len(saved)} invoice(s) saved to {Config.OUTPUT_DIR}")
if __name__ == "__main__":
main()