Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielturus/41cfb2f74d77b687aa3488e1c07daa05 to your computer and use it in GitHub Desktop.
Save danielturus/41cfb2f74d77b687aa3488e1c07daa05 to your computer and use it in GitHub Desktop.
import json
import requests
# Read package.json file
with open('package.json', 'r') as file:
package_json = json.load(file)
# Extract dependencies and their versions
dependencies = package_json.get('dependencies', {})
# Create markdown table header
markdown_table = "| Package | Version | License |\n|---------|---------|---------|\n"
# Iterate over each dependency
for package_name, package_version in dependencies.items():
# Search for license using npm registry API
response = requests.get(f'https://registry.npmjs.org/{package_name}/{package_version}')
if response.status_code == 200:
license_info = response.json().get('license', 'License information not found')
else:
license_info = 'Failed to retrieve license information'
# Add package details to the markdown table
markdown_table += f"| {package_name} | {package_version} | {license_info} |\n"
# Write the markdown table to a file
with open('package_licenses.md', 'w') as file:
file.write(markdown_table)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment