You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
720 B
Python
23 lines
720 B
Python
import os
|
|
import json
|
|
from jinja2 import Environment, FileSystemLoader
|
|
|
|
# Charger les données JSON
|
|
with open('invoice_data.json', 'r') as file:
|
|
invoice_data = json.load(file)
|
|
|
|
# Configurer Jinja2
|
|
env = Environment(loader=FileSystemLoader('.'))
|
|
template = env.get_template('invoice_template.html')
|
|
|
|
# Créer le dossier 'facture' s'il n'existe pas
|
|
os.makedirs('facture', exist_ok=True)
|
|
|
|
# Générer les fichiers HTML pour chaque facture
|
|
for data in invoice_data:
|
|
html_output = template.render(data)
|
|
invoice_filename = f"invoices/{data['invoice_number']}.html"
|
|
with open(invoice_filename, 'w') as file:
|
|
file.write(html_output)
|
|
|
|
print("Les factures ont été générées dans le dossier 'facture'.") |