Tunnels.fetch_codes

Tunnels.fetch_codes(page_no=None, update=False, dump_dir=None, verbose=False, **kwargs)[source]

Fetch data of railway tunnel lengths.

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

  • update (bool) – Whether to check for updates to the package data; defaults to False.

  • dump_dir (str | None) – The path to a directory where the data file will be saved. Defaults to None.

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

Returns:

A dictionary containing the data of tunnel lengths (including the name, length, owner and relative location) and the date of when the data was last updated.

Return type:

dict | None

Examples:

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

>>> tunl = Tunnels()

>>> tunnels_lengths_data: dict = tunl.fetch_codes()

>>> list(tunnels_lengths_data)
['Tunnels', 'Last updated date']
>>> tunl.KEY
'Tunnels'

>>> tunnels_lengths_dat = tunnels_lengths_data[tunl.KEY]
>>> type(tunnels_lengths_dat)
dict
>>> list(tunnels_lengths_dat.keys())
['Page 1 (A-F)', 'Page 2 (G-P)', 'Page 3 (Q-Z)', 'Page 4 (others)']

>>> tunnels_page_1_codes = tunnels_lengths_dat['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]