'How to fetch data from json file into invoice generator library of python...? In Invoice generator library I dont want to add data manually

Below given is the python code I used to create invoice :

    import os

    from InvoiceGenerator.api import Invoice, Item, Client, Provider, Creator
    from InvoiceGenerator.pdf import SimpleInvoice


    # choose english as language
    os.environ["INVOICE_LANG"] = "en"

    client = Client('ROHIT RAJ')
    provider = Provider('MANIAR TYREWORLD', bank_account='2600420569', bank_code='2010')
    creator = Creator('DHIREN AHUJA')

    invoice = Invoice(client, provider, creator)
    invoice.currency_locale = 'en_US.UTF-8'
    invoice.add_item(Item(32, 600, description="Item 1"))
    invoice.add_item(Item(60, 50, description="Item 2", tax=21))
    invoice.add_item(Item(50, 60, description="Item 3", tax=0))
    invoice.add_item(Item(5, 600, description="Item 4", tax=15))

    pdf = SimpleInvoice(invoice)
    pdf.gen("invoice.pdf", generate_qr_code=True)

The above given code i used for generating an invoice and below given code i used to parse the data from json file.

    #import packages
    import json
    from json2html import*

    #Now open json file
    with open('trying.json') as f:
    d = json.load(f) # Load our json file
    scanoutput = json2html.convert(json=d) # It will convert Json to html
    htmlReportFile = "tryingf.html" # Write your desired file name to create output file
    with open(htmlReportFile, 'w') as htmlfile: # Open output file into write mode
    htmlfile.write(str(scanoutput)) # Write converted json into our created html file
    print("Json file is converted into html successfully...")

Simply I need to merge both of these programs so that invoice generator library can fetch the data automatically. Anyone can help ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source