Tunnels¶
A class for collecting railway tunnel lengths.
Tunnels.parse_tunnel_length (x) |
Parse data in 'Length' column, i.e. |
Tunnels.collect_railway_tunnel_lengths_by_page (page_no) |
Collect data of railway tunnel lengths for a given page number from source web page. |
Tunnels.fetch_railway_tunnel_lengths ([…]) |
Fetch data of railway tunnel lengths from local backup. |
-
class
pyrcs.other_assets.
Tunnels
(data_dir=None, update=False)[source]¶ A class for collecting railway tunnel lengths.
Parameters: - data_dir (str, None) – name of data directory, defaults to
None
- update (bool) – whether to check on update and proceed to update the package data, defaults to
False
Example:
from pyrcs.other_assets import Tunnels tunnels = Tunnels() print(tunnels.Name) # Railway tunnel lengths print(tunnels.SourceURL) # http://www.railwaycodes.org.uk/tunnels/tunnels0.shtm
-
static
parse_tunnel_length
(x)[source]¶ Parse data in
'Length'
column, i.e. convert miles/yards to metres.Parameters: x (str, None) – raw length data Returns: parsed length data and, if any, additional information associated with it Return type: tuple Examples:
from pyrcs.other_assets import Tunnels tunnels = Tunnels() tunnels.parse_tunnel_length('') # (nan, 'Unavailable') tunnels.parse_tunnel_length('1m 182y') # (1775.7648, None) tunnels.parse_tunnel_length('formerly 0m236y') # (215.7984, 'Formerly') tunnels.parse_tunnel_length('0.325km (0m 356y)') # (325.5264, '0.325km') tunnels.parse_tunnel_length("0m 48yd- (['0m 58yd'])") # (48.4632, '43.89-53.04 metres')
-
collect_railway_tunnel_lengths_by_page
(page_no, update=False, verbose=False)[source]¶ Collect data of railway tunnel lengths for a given page number from source web page.
Parameters: - page_no (int, str) – page number; valid values include 1, 2, 3 and 4
- update (bool) – whether to check on update and proceed to update the package data, defaults to
False
- verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to
False
Returns: tunnel lengths data of the given
page_no
and date of when the data was last updatedReturn type: dict
Examples:
from pyrcs.other_assets import Tunnels tunnels = Tunnels() update = True page_no = 1 railway_tunnel_lengths_1 = tunnels.collect_railway_tunnel_lengths_by_page(page_no, update) print(railway_tunnel_lengths_1) # {'Page 1 (A-F)': <codes>, # 'Last updated date': <date>} page_no = 4 railway_tunnel_lengths_4 = tunnels.collect_railway_tunnel_lengths_by_page(page_no, update) print(railway_tunnel_lengths_4) # {'Page 4 (others)': <codes>, # 'Last updated date': <date>}
-
fetch_railway_tunnel_lengths
(update=False, pickle_it=False, data_dir=None, verbose=False)[source]¶ Fetch data of railway tunnel lengths from local backup.
Parameters: - update (bool) – whether to check on update and proceed to update the package data, defaults to
False
- pickle_it (bool) – whether to replace the current package data with newly collected data, defaults to
False
- data_dir (str, None) – name of package data folder, defaults to
None
- verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to
False
Returns: railway tunnel lengths data (including the name, length, owner and relative location) and date of when the data was last updated
Return type: dict
Example:
from pyrcs.other_assets import Tunnels tunnels = Tunnels() update = False pickle_it = False data_dir = None railway_tunnel_lengths = tunnels.fetch_railway_tunnel_lengths(update, pickle_it, data_dir) print(railway_tunnel_lengths) # {'Tunnels': <codes>, # 'Latest update date': <date>}
- update (bool) – whether to check on update and proceed to update the package data, defaults to
- data_dir (str, None) – name of data directory, defaults to