Skip to content

Commit 88a018d

Browse files
authored
validate id and name (#8)
1 parent 24442b7 commit 88a018d

1 file changed

Lines changed: 22 additions & 9 deletions

File tree

.github/workflows/validate_missing.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,48 @@
22
import sys
33

44
def main():
5-
# Load IDs from mapping.csv
5+
# Load mapping of motis_id to motis_name from mapping.csv
66
try:
77
with open("mapping.csv", newline="", encoding="utf-8") as mapping_file:
88
mapping_reader = csv.DictReader(mapping_file)
9-
mapping_ids = {row["motis_id"].strip() for row in mapping_reader if row.get("motis_id")}
9+
mapping_dict = {}
10+
for row in mapping_reader:
11+
mid = row.get("motis_id", "").strip()
12+
mname = row.get("motis_name", "").strip()
13+
if mid and mname:
14+
mapping_dict[mid] = mname
1015
except FileNotFoundError:
1116
print("Error: mapping.csv file not found.")
1217
sys.exit(1)
1318

14-
# Load IDs from missing.csv
19+
# Load missing entries as a list of (motis_id, name) tuples from missing.csv
1520
try:
1621
with open("missing.csv", newline="", encoding="utf-8") as missing_file:
1722
missing_reader = csv.DictReader(missing_file)
18-
missing_ids = [row["motis_id"].strip() for row in missing_reader if row.get("motis_id")]
23+
missing_list = []
24+
for row in missing_reader:
25+
mid = row.get("motis_id", "").strip()
26+
name = row.get("name", "").strip()
27+
if mid and name:
28+
missing_list.append((mid, name))
1929
except FileNotFoundError:
2030
print("Error: missing.csv file not found.")
2131
sys.exit(1)
2232

23-
# Check each ID from missing.csv to see if it is also in mapping.csv
33+
# Check: if (motis_id, name) from missing.csv exists AND the same motis_id with this motis_name
34+
# is in mapping.csv, report an error
2435
failed = False
25-
for missing_id in missing_ids:
26-
if missing_id in mapping_ids:
27-
print(f"Error: ID '{missing_id}' found in both mapping.csv and missing.csv. It's obviously not missing, so should be removed from missing.csv.")
36+
for mid, name in missing_list:
37+
mapped_name = mapping_dict.get(mid)
38+
if mapped_name and mapped_name == name:
39+
print(f"Error: Combination motis_id='{mid}' and name='{name}' is listed in missing.csv, "
40+
f"but also present in mapping.csv (motis_name='{mapped_name}').")
2841
failed = True
2942

3043
if failed:
3144
sys.exit(1)
3245
else:
33-
print("All IDs in missing.csv are not present in mapping.csv.")
46+
print("All clear: No matching motis_id,name combinations found in both files.")
3447

3548
if __name__ == "__main__":
3649
main()

0 commit comments

Comments
 (0)