|
2 | 2 | import sys |
3 | 3 |
|
4 | 4 | def main(): |
5 | | - # Load IDs from mapping.csv |
| 5 | + # Load mapping of motis_id to motis_name from mapping.csv |
6 | 6 | try: |
7 | 7 | with open("mapping.csv", newline="", encoding="utf-8") as mapping_file: |
8 | 8 | 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 |
10 | 15 | except FileNotFoundError: |
11 | 16 | print("Error: mapping.csv file not found.") |
12 | 17 | sys.exit(1) |
13 | 18 |
|
14 | | - # Load IDs from missing.csv |
| 19 | + # Load missing entries as a list of (motis_id, name) tuples from missing.csv |
15 | 20 | try: |
16 | 21 | with open("missing.csv", newline="", encoding="utf-8") as missing_file: |
17 | 22 | 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)) |
19 | 29 | except FileNotFoundError: |
20 | 30 | print("Error: missing.csv file not found.") |
21 | 31 | sys.exit(1) |
22 | 32 |
|
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 |
24 | 35 | 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}').") |
28 | 41 | failed = True |
29 | 42 |
|
30 | 43 | if failed: |
31 | 44 | sys.exit(1) |
32 | 45 | 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.") |
34 | 47 |
|
35 | 48 | if __name__ == "__main__": |
36 | 49 | main() |
0 commit comments