Update to accept snakecase license_name for futher compatibility.
Browse files- scripts/make_licenses.py +9 -5
scripts/make_licenses.py
CHANGED
|
@@ -51,10 +51,14 @@ def main(src_csv, dest_dir):
|
|
| 51 |
except Exception as e:
|
| 52 |
sys.exit(e)
|
| 53 |
|
| 54 |
-
# Check for "License Name" column
|
| 55 |
print("Processing data")
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# Check filepath given by user
|
| 60 |
dest_dir_path = Path(dest_dir)
|
|
@@ -69,7 +73,7 @@ def main(src_csv, dest_dir):
|
|
| 69 |
|
| 70 |
# Add links for licenses to catalog manifest
|
| 71 |
print("Getting URLs for licenses")
|
| 72 |
-
df["license_link"] = df[
|
| 73 |
|
| 74 |
# Save license file
|
| 75 |
df.to_csv(str(filepath / "licenses.csv"), index=False)
|
|
@@ -77,7 +81,7 @@ def main(src_csv, dest_dir):
|
|
| 77 |
# Print counts of licenses for which URL was not resolved
|
| 78 |
print(
|
| 79 |
"Licenses with no URL: \n",
|
| 80 |
-
df.loc[df["license_link"].isna(),
|
| 81 |
)
|
| 82 |
|
| 83 |
|
|
|
|
| 51 |
except Exception as e:
|
| 52 |
sys.exit(e)
|
| 53 |
|
| 54 |
+
# Check for "License Name" or "license_name" column
|
| 55 |
print("Processing data")
|
| 56 |
+
df_cols = list(df.columns)
|
| 57 |
+
if "License Name" not in df_cols:
|
| 58 |
+
if "license_name" not in df_cols:
|
| 59 |
+
sys.exit("Source CSV does not have a column labeled License Name or license_name.")
|
| 60 |
+
license_col = "license_name"
|
| 61 |
+
license_col = "License Name"
|
| 62 |
|
| 63 |
# Check filepath given by user
|
| 64 |
dest_dir_path = Path(dest_dir)
|
|
|
|
| 73 |
|
| 74 |
# Add links for licenses to catalog manifest
|
| 75 |
print("Getting URLs for licenses")
|
| 76 |
+
df["license_link"] = df[license_col].apply(get_license_url)
|
| 77 |
|
| 78 |
# Save license file
|
| 79 |
df.to_csv(str(filepath / "licenses.csv"), index=False)
|
|
|
|
| 81 |
# Print counts of licenses for which URL was not resolved
|
| 82 |
print(
|
| 83 |
"Licenses with no URL: \n",
|
| 84 |
+
df.loc[df["license_link"].isna(), license_col].value_counts(),
|
| 85 |
)
|
| 86 |
|
| 87 |
|