Tunnels.collect_codes

Tunnels.collect_codes(page_no, confirmation_required=True, verbose=False, raise_error=False)[source]

Collect data of railway tunnel lengths for a specific page from the source web page.

This method coordinates the retrieval process by requesting the target page from the source and parsing the structural table information.

Parameters:
  • page_no (int | str) – The page number to collect data from; valid values are 1, 2, 3 and 4.

  • confirmation_required (bool) – Whether user confirmation is required; if True (default), prompts the user before proceeding.

  • verbose (bool | int) – Whether to print status information to the console. Defaults to False.

  • raise_error (bool) – Whether to raise exceptions encountered during retrieval; if False (default), errors are suppressed.

Returns:

A dictionary containing the tunnel length data and the last updated date.

Return type:

dict | None

Examples:

>>> from pyrcs.other_assets import Tunnels  # from pyrcs import Tunnels

>>> tunl = Tunnels()

>>> tunnels_page_1_data: dict = tunl.collect_codes(page_no=1, verbose=True)
Proceed with collecting data of railway tunnel lengths (Page 1 (A-F))?
 [No]|Yes: yes
Collecting the data ... Done.

>>> list(tunnels_page_1_data)
['Page 1 (A-F)', 'Last updated date']

>>> tunnels_page_1_codes = tunnels_page_1_data['Page 1 (A-F)']

>>> type(tunnels_page_1_codes)
pandas.DataFrame
>>> tunnels_page_1_codes.shape
(777, 11)
>>> tunnels_page_1_codes.head()
             Name  Other names, remarks  ... Length (metres) Length (note)
0    Abbotscliffe                        ...       1775.7648
1      Abercanaid           see Merthyr  ...             NaN   Unavailable
2     Aberchalder         see Loch Oich  ...             NaN   Unavailable
3  Aberdovey No 1  also called Frongoch  ...          182.88
4  Aberdovey No 2    also called Morfor  ...        200.2536
[5 rows x 11 columns]

>>> tunnels_page_4_data: dict = tunl.collect_codes(page_no=4, verbose=True)
Proceed with collecting data of railway tunnel lengths (Page 4 (others))?
 [No]|Yes: yes
Collecting the data ... Done.

>>> list(tunnels_page_4_data)
['Page 4 (others)', 'Last updated date']
>>> tunnels_page_4_codes = tunnels_page_4_data['Page 4 (others)']

>>> type(tunnels_page_4_codes)
dict
>>> list(tunnels_page_4_codes)
['Tunnels on industrial and other minor lines',
 'Large bridges that are not officially tunnels but could appear to be so']

>>> page_4_1 = tunnels_page_4_codes['Tunnels on industrial and other minor lines']
>>> type(page_4_1)
pandas.DataFrame
>>> page_4_1.shape
(107, 6)
>>> page_4_1.head()
                      Name Other names, remarks  ... Length (metres) Length (note)
0             Ashes Quarry                       ...         56.6928
1        Ashey Down Quarry                       ...         33.8328
2  Baileycroft Quarry No 1                       ...         28.3464
3  Baileycroft Quarry No 2                       ...         21.0312
4            Basfords Hill                       ...         46.6344
[5 rows x 6 columns]

>>> page_4_2 = tunnels_page_4_codes[
...     'Large bridges that are not officially tunnels but could appear to be so']
>>> type(page_4_2)
pandas.DataFrame
>>> page_4_2.shape
(16, 8)
>>> page_4_2.head()
                Name Other names, remarks  ... Length (metres) Length (note)
0  A470/A472 (north)                       ...         35.6616
1  A470/A472 (south)                       ...         28.3464
2               A720                       ...        145.3896
3                 A9        Aberdeen line  ...         141.732
4                 A9           Perth line  ...         146.304
[5 rows x 8 columns]