ELRMileages.collect_mileage_file¶
- ELRMileages.collect_mileage_file(elr, parsed=True, confirmation_required=True, dump_dir=False, verbose=False, raise_error=False)[source]¶
Collect the mileage file for a specific ELR from the source web page.
- Parameters:
elr (str) – The ELR for which the mileage file is requested (e.g.
'CJD','MLA','FED').parsed (bool) – Whether to parse the scraped mileage data; defaults to
True.confirmation_required (bool) – Whether user confirmation is required; if
confirmation_required=True(default), prompts the user for confirmation before proceeding with data collection.dump_dir (str | os.PathLike | bool | None) – The path to a directory where the mileage file data is saved; if
False(default), the data will not be dumped.verbose (bool | int) – Whether to print relevant information to the console; defaults to
False.raise_error (bool) – Whether to raise the provided exception; if
raise_error=False(default), the error will be suppressed.
- Returns:
A dictionary containing the mileage file for the specified ELR.
- Return type:
dict | None
Note
In some cases, mileages may be unknown and thus left blank (e.g.
'ANI2, Orton Junction with ROB (~3.05)').Mileages in parentheses are not on that ELR but are included for reference (e.g.
'ANL, (8.67) NORTHOLT [London Underground]').As with the main ELR list, mileages preceded by a tilde (~) are approximate.
Examples:
>>> from pyrcs.line_data import ELRMileages # from pyrcs import ELRMileages >>> em = ELRMileages() >>> gam_mileage_file = em.collect_mileage_file(elr='GAM', verbose=True) Proceed with collecting the mileage file of "GAM"? [No]|Yes: yes Collecting the mileage file ... Not available. >>> xrc2_mileage_file = em.collect_mileage_file(elr='XRC2', verbose=True) Proceed with collecting the mileage file of "XRC2"? [No]|Yes: yes Collecting the mileage file ... Done. >>> xrc2_mileage_file['Mileage'] Mileage Mileage_Note ... Link_1_ELR Link_1_Mile_Chain 0 9.0158 14.629km ... 1 9.0447 14.893km ... 2 9.0557 14.994km ... [3 rows x 8 columns] >>> xre_mileage_file = em.collect_mileage_file(elr='XRE', verbose=True) Proceed with collecting the mileage file of "XRE"? [No]|Yes: yes Collecting the mileage file ... Done. >>> xre_mileage_file['Mileage'] Mileage Mileage_Note ... Link_2_ELR Link_2_Mile_Chain 0 7.0073 11.333km ... 1 7.0174 11.425km ... 2 9.0158 14.629km ... 3 9.0198 14.666km ... 4 9.0389 14.840km ... 5 9.0439 (14.886)km ... 6 9.0540 (14.978)km ... [7 rows x 11 columns] >>> mor_mileage_file = em.collect_mileage_file(elr='MOR', verbose=True) Proceed with collecting the mileage file of "MOR"? [No]|Yes: yes Collecting the mileage file ... Done. >>> mor_mileage_file_data = mor_mileage_file['Mileage'] >>> list(mor_mileage_file_data) ['Original measure', 'Later measure'] >>> mor_mileage_file_data['Original measure'] Mileage Mileage_Note Miles_Chains ... Link_1 Link_1_ELR Link_1_Mile_Chain 0 0.0000 0.00 ... SWA (215.18) SWA 215.18 1 0.0242 0.11 ... 2 0.0572 0.26 ... 3 0.0792 0.36 ... 4 0.1078 0.49 ... 5 0.1716 0.78 ... 6 1.1166 1.53 ... 7 2.0066 2.03 ... 8 2.0836 2.38 ... 9 ... 10 3.0462 3.21 ... SDI2 (2.79) SDI2 2.79 [11 rows x 8 columns] >>> mor_mileage_file_data['Later measure'] Mileage Mileage_Note Miles_Chains ... Link_1 Link_1_ELR Link_1_Mile_Chain 0 0.0000 0.00 ... SWA (215.26) SWA 215.26 1 0.0176 0.08 ... SWA (215.18) SWA 215.18 2 0.0418 0.19 ... 3 0.0748 0.34 ... 4 0.0968 0.44 ... 5 0.1254 0.57 ... 6 1.0132 1.06 ... 7 1.1342 1.61 ... 8 2.0242 2.11 ... 9 2.1012 2.46 ... 10 ... 11 3.0638 3.29 ... SDI2 (2.79) SDI2 2.79 [12 rows x 8 columns] >>> fed_mileage_file = em.collect_mileage_file(elr='FED', verbose=True) Proceed with collecting the mileage file of "FED"? [No]|Yes: yes Collecting the mileage file ... Done. >>> fed_mileage_file_data = fed_mileage_file['Mileage'] >>> list(fed_mileage_file_data) ['Current measure', 'Original route'] >>> fed_mileage_file_data['Current measure'] Mileage Mileage_Note ... Link_1_ELR Link_1_Mile_Chain 0 83.1254 ... FEL 1 84.0198 ... 2 84.1430 ... 3 84.1540 ... 4 85.0484 ... 5 85.1122 ... 6 85.1188 ... TFN 2.13 [7 rows x 8 columns] >>> fed_mileage_file_data['Original route'] Mileage Mileage_Note Miles_Chains ... Link_1 Link_1_ELR Link_1_Mile_Chain 0 0.0000 0.00 ... FEL (84.22) FEL 84.22 1 1.0176 1.08 ... 2 1.1540 1.70 ... 3 1.1694 1.77 ... [4 rows x 8 columns]