-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd5f479
commit 76b1a70
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
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
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}") | ||
|
||
|