Created
September 16, 2019 14:35
-
-
Save gruia-dev/aa7f6332fc9b40c8f4799e3990e8f70a to your computer and use it in GitHub Desktop.
saving licenses from JSON file(built using pip-licenses) in excel
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
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment