Skip to content

Instantly share code, notes, and snippets.

@gruia-dev
Created September 16, 2019 14:35
Show Gist options
  • Save gruia-dev/aa7f6332fc9b40c8f4799e3990e8f70a to your computer and use it in GitHub Desktop.
Save gruia-dev/aa7f6332fc9b40c8f4799e3990e8f70a to your computer and use it in GitHub Desktop.

Revisions

  1. gruia-dev created this gist Sep 16, 2019.
    35 changes: 35 additions & 0 deletions licenses.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    import json

    import xlsxwriter


    def main():
    """
    for exporting licenses in json file execute
    pip-licenses --order=license --format=json > licenses.json
    Note! pip-licenses must be installed in the environment
    """
    workbook = xlsxwriter.Workbook('licenses.xlsx')
    worksheet = workbook.add_worksheet()
    bold = workbook.add_format({'bold': True})

    # Text with formatting.
    worksheet.write('A1', 'Name', bold)
    worksheet.write('B1', 'Version', bold)
    worksheet.write('C1', 'License', bold)

    with open('licenses.json') as json_file:
    data = json.load(json_file)
    print(data)
    print(len(data))
    for idx, _license in enumerate(data):
    i = idx + 1
    worksheet.write(i, 0, _license.get('Name'))
    worksheet.write(i, 1, _license.get('Version'))
    worksheet.write(i, 2, _license.get('License'))

    workbook.close()


    if __name__ == '__main__':
    main()