Skip to content

Commit 33fa723

Browse files
committed
Replace 'fh' with 'file_object' for descriptive variable naming
1 parent 29856ee commit 33fa723

1 file changed

Lines changed: 14 additions & 14 deletions

File tree

scripts/1-fetch/doaj_fetch.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ def load_country_names():
179179
)
180180

181181
try:
182-
with open(country_file, "r", encoding="utf-8") as fh:
183-
countries = yaml.safe_load(fh)
182+
with open(country_file, "r", encoding="utf-8") as file_object:
183+
countries = yaml.safe_load(file_object)
184184
return {country["code"]: country["name"] for country in countries}
185185
except Exception as e:
186186
LOGGER.error(f"Failed to load country codes from {country_file}: {e}")
@@ -409,18 +409,18 @@ def save_count_data(
409409
country_names = load_country_names()
410410

411411
# Save license counts
412-
with open(FILE_DOAJ_COUNT, "w", encoding="utf-8", newline="\n") as fh:
413-
writer = csv.DictWriter(fh, fieldnames=HEADER_COUNT, dialect="unix")
412+
with open(FILE_DOAJ_COUNT, "w", encoding="utf-8", newline="\n") as file_object:
413+
writer = csv.DictWriter(file_object, fieldnames=HEADER_COUNT, dialect="unix")
414414
writer.writeheader()
415415
for lic, count in license_counts.items():
416416
writer.writerow({"TOOL_IDENTIFIER": lic, "COUNT": count})
417417

418418
# Save subject report
419419
with open(
420420
FILE_DOAJ_SUBJECT_REPORT, "w", encoding="utf-8", newline="\n"
421-
) as fh:
421+
) as file_object:
422422
writer = csv.DictWriter(
423-
fh, fieldnames=HEADER_SUBJECT_REPORT, dialect="unix"
423+
file_object, fieldnames=HEADER_SUBJECT_REPORT, dialect="unix"
424424
)
425425
writer.writeheader()
426426
for lic, subjects in subject_counts.items():
@@ -439,8 +439,8 @@ def save_count_data(
439439
)
440440

441441
# Save language counts with readable names
442-
with open(FILE_DOAJ_LANGUAGE, "w", encoding="utf-8", newline="\n") as fh:
443-
writer = csv.DictWriter(fh, fieldnames=HEADER_LANGUAGE, dialect="unix")
442+
with open(FILE_DOAJ_LANGUAGE, "w", encoding="utf-8", newline="\n") as file_object:
443+
writer = csv.DictWriter(file_object, fieldnames=HEADER_LANGUAGE, dialect="unix")
444444
writer.writeheader()
445445
for lic, languages in language_counts.items():
446446
for lang_code, count in languages.items():
@@ -455,8 +455,8 @@ def save_count_data(
455455
)
456456

457457
# Save year counts
458-
with open(FILE_DOAJ_YEAR, "w", encoding="utf-8", newline="\n") as fh:
459-
writer = csv.DictWriter(fh, fieldnames=HEADER_YEAR, dialect="unix")
458+
with open(FILE_DOAJ_YEAR, "w", encoding="utf-8", newline="\n") as file_object:
459+
writer = csv.DictWriter(file_object, fieldnames=HEADER_YEAR, dialect="unix")
460460
writer.writeheader()
461461
for lic, years in year_counts.items():
462462
for year, count in years.items():
@@ -465,9 +465,9 @@ def save_count_data(
465465
)
466466

467467
# Save publisher counts
468-
with open(FILE_DOAJ_PUBLISHER, "w", encoding="utf-8", newline="\n") as fh:
468+
with open(FILE_DOAJ_PUBLISHER, "w", encoding="utf-8", newline="\n") as file_object:
469469
writer = csv.DictWriter(
470-
fh, fieldnames=HEADER_PUBLISHER, dialect="unix"
470+
file_object, fieldnames=HEADER_PUBLISHER, dialect="unix"
471471
)
472472
writer.writeheader()
473473
for lic, publishers in publisher_counts.items():
@@ -529,8 +529,8 @@ def query_doaj(args):
529529
}
530530

531531
try:
532-
with open(FILE_PROVENANCE, "w", encoding="utf-8", newline="\n") as fh:
533-
yaml.dump(provenance_data, fh, default_flow_style=False, indent=2)
532+
with open(FILE_PROVENANCE, "w", encoding="utf-8", newline="\n") as file_object:
533+
yaml.dump(provenance_data, file_object, default_flow_style=False, indent=2)
534534
except Exception as e:
535535
LOGGER.error("Failed to write provenance file: %s", e)
536536
raise shared.QuantifyingException(

0 commit comments

Comments
 (0)