Created
May 29, 2023 12:16
-
-
Save danielturus/41cfb2f74d77b687aa3488e1c07daa05 to your computer and use it in GitHub Desktop.
This file contains 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 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