1
0
mirror of https://github.com/ilri/csv-metadata-quality.git synced 2024-11-24 14:50:17 +01:00

Don't crash when title is missing

We shouldn't crash the country/region checker/fixer when the title
field is missing, since we only use it to show status to the user.
This commit is contained in:
Alan Orth 2023-06-12 10:33:50 +03:00
parent 1fa81f7558
commit f3fb1ff7fb
3 changed files with 20 additions and 6 deletions

View File

@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`dcterms.bibliographicCitation` fields `dcterms.bibliographicCitation` fields
- Fixed regex so we run the comma space fix on `dcterms.bibliographicCitation` - Fixed regex so we run the comma space fix on `dcterms.bibliographicCitation`
fields fields
- Don't crash the country/region checker/fixer when a title field is missing
### Changed ### Changed
- Don't run newline fix on description fields - Don't run newline fix on description fields

View File

@ -563,8 +563,13 @@ def countries_match_regions(row, exclude):
un_region = cc.convert(names=country, to="UNRegion") un_region = cc.convert(names=country, to="UNRegion")
if un_region != "not found" and un_region not in regions: if un_region != "not found" and un_region not in regions:
print( try:
f"{Fore.YELLOW}Missing region ({country} → {un_region}): {Fore.RESET}{row[title_column_name]}" print(
) f"{Fore.YELLOW}Missing region ({country} → {un_region}): {Fore.RESET}{row[title_column_name]}"
)
except KeyError:
print(
f"{Fore.YELLOW}Missing region ({country} → {un_region}): {Fore.RESET}<title field not present>"
)
return return

View File

@ -370,9 +370,17 @@ def countries_match_regions(row, exclude):
# it doesn't already exist in regions. # it doesn't already exist in regions.
if un_region != "not found" and un_region not in regions: if un_region != "not found" and un_region not in regions:
if un_region not in missing_regions: if un_region not in missing_regions:
print( try:
f"{Fore.YELLOW}Adding missing region ({un_region}): {Fore.RESET}{row[title_column_name]}" print(
) f"{Fore.YELLOW}Adding missing region ({un_region}): {Fore.RESET}{row[title_column_name]}"
)
except KeyError:
# If there is no title column in the CSV we will print
# the fix without the title instead of crashing.
print(
f"{Fore.YELLOW}Adding missing region ({un_region}): {Fore.RESET}<title field not present>"
)
missing_regions.append(un_region) missing_regions.append(un_region)
if len(missing_regions) > 0: if len(missing_regions) > 0: