Skip to content

Commit

Permalink
feat: acquire licence text
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyharrison committed Apr 26, 2024
1 parent fd5f479 commit 76b1a70
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tools/get_license_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import json
import requests

license_dir, filename = os.path.split(__file__)
# Bodge the pathname
license_path = os.path.join(license_dir, "../lib4sbom/license_data", "spdx_licenses.json")
licfile = open(license_path, "r", encoding="utf-8")
licenses = json.load(licfile)

# Process each licence
for lic in licenses["licenses"]:
#print (lic)
id = lic["licenseId"].lower()
name = lic["name"].lower()
url = lic["detailsUrl"]
print (f"{name} - {id}: {url}")

filename=f"{id}.txt"
file_path = os.path.join(license_dir, "../lib4sbom/license_data/text", filename)
# Get text
try:
license_text = requests.get(url).json()
if license_text.get("licenseText") is not None:
#text=license_text["licenseText"]
html=license_text["licenseTextHtml"]
#print (html)
# Create file
with open(file_path,"w") as f:
f.write(html)
except requests.exceptions.RequestException:
print (f"Unable to find license text for {name}")


0 comments on commit 76b1a70

Please sign in to comment.