LOR

A class for collecting line of route (LOR) codes.

LOR.get_keys_to_prefixes([prefixes_only, …]) Get key to LOR code prefixes.
LOR.get_lor_page_urls([update, verbose]) Get URLs to LOR codes with different prefixes.
LOR.update_catalogue([…]) Update catalogue data including keys to prefixes and LOR page URLs.
LOR.collect_lor_codes_by_prefix(prefix[, …]) Collect LOR codes by a given prefix.
LOR.fetch_lor_codes([update, pickle_it, …]) Fetch LOR codes from local backup.
LOR.collect_elr_lor_converter([…]) Collect ELR/LOR converter from source web page.
LOR.fetch_elr_lor_converter([update, …]) Fetch ELR/LOR converter from local backup.
class pyrcs.line_data.LOR(data_dir=None, update=False)[source]

A class for collecting line of route (LOR) codes.

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.line_data import LOR

lor = LOR()

print(lor.Name)
# Line of Route (LOR/PRIDE) codes

print(lor.SourceURL)
# http://www.railwaycodes.org.uk/pride/pride0.shtm
get_keys_to_prefixes(prefixes_only=True, update=False, verbose=False)[source]

Get key to LOR code prefixes.

Parameters:
  • prefixes_only (bool) – whether to get only prefixes, defaults to True
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • verbose (bool) – whether to print relevant information in console as the function runs, defaults to False
Returns:

keys to LOR code prefixes

Return type:

list, dict

Examples:

from pyrcs.line_data import LOR

lor = LOR()

prefixes_only = True
keys_to_prefixes = lor.get_keys_to_prefixes(prefixes_only)
print(keys_to_prefixes)
# ['CY', 'EA', 'GW', 'LN', 'MD', 'NW', 'NZ', 'SC', 'SO', 'SW', 'XR']

prefixes_only = False
keys_to_prefixes = lor.get_keys_to_prefixes(prefixes_only)
print(keys_to_prefixes)
# {'Key to prefixes': <data frame of keys to prefixes>,
#  'Last update date': <date>}
get_lor_page_urls(update=False, verbose=False)[source]

Get URLs to LOR codes with different prefixes.

Parameters:
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • verbose (bool) – whether to print relevant information in console as the function runs, defaults to False
Returns:

a list of URLs of web pages hosting LOR codes for each prefix

Return type:

list

Example:

from pyrcs.line_data import LOR

lor = LOR()

lor_page_urls = lor.get_lor_page_urls()
print(lor_page_urls)
# <a list of URLs>
update_catalogue(confirmation_required=True, verbose=False)[source]

Update catalogue data including keys to prefixes and LOR page URLs.

Parameters:
  • confirmation_required (bool) – whether to require users to confirm and proceed, defaults to True
  • verbose (bool) – whether to print relevant information in console as the function runs, defaults to False
collect_lor_codes_by_prefix(prefix, update=False, verbose=False)[source]

Collect LOR codes by a given prefix.

Parameters:
  • prefix (str) – prefix of LOR codes
  • update (bool) – whether to check on update and proceed to update the package data, defaults to False
  • verbose (bool) – whether to print relevant information in console as the function runs, defaults to False
Returns:

LOR codes for the given prefix

Return type:

dict, None

Examples:

from pyrcs.line_data import LOR

lor = LOR()

prefix = 'CY'
update = False
lor_codes_cy = lor.collect_lor_codes_by_prefix(prefix, update)
print(lor_codes_cy)
# {'CY': <codes>,
#  'Notes': <notes>,
#  'Last updated date': <date>}

prefix = 'NW'
update = False
lor_codes_nw = lor.collect_lor_codes_by_prefix(prefix, update)
print(lor_codes_nw)
# {'NW/NZ': <codes>,
#  'Notes': <codes>,
#  'Last updated date': <date>}

prefix = 'EA'
update = True
lor_codes_ea = lor.collect_lor_codes_by_prefix(prefix, update)
print(lor_codes_ea)
# {'EA': <codes>,
#  'Last updated date': <date>}
fetch_lor_codes(update=False, pickle_it=False, data_dir=None, verbose=False)[source]

Fetch LOR codes 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) – whether to print relevant information in console as the function runs, defaults to False
Returns:

LOR codes

Return type:

dict

Example:

from pyrcs.line_data import LOR

lor = LOR()

update = False
pickle_it = False
data_dir = None

lor_codes_data = lor.fetch_lor_codes(update, pickle_it, data_dir)

print(lor_codes_data)
# {'LOR': <codes>,
#  'Last_updated_date': <date>}
collect_elr_lor_converter(confirmation_required=True, verbose=False)[source]

Collect ELR/LOR converter from source web page.

Parameters:
  • confirmation_required (bool) – whether to require users to confirm and proceed, defaults to True
  • verbose (bool) – whether to print relevant information in console as the function runs, defaults to False
Returns:

data of ELR/LOR converter

Return type:

dict, None

Example:

from pyrcs.line_data import LOR

lor = LOR()

confirmation_required = True

elr_lor_converter = lor.collect_elr_lor_converter(confirmation_required)
# To collect "ELR/LOR converter"?  [No]|Yes:
# >? yes

print(elr_lor_converter)
# {'ELR/LOR converter': <codes>,
#  'Last updated date': <date>}
fetch_elr_lor_converter(update=False, pickle_it=False, data_dir=None, verbose=False)[source]

Fetch ELR/LOR converter 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) – whether to print relevant information in console as the function runs, defaults to False
Returns:

data of ELR/LOR converter

Return type:

dict

Example:

from pyrcs.line_data import LOR

lor = LOR()

update = False
pickle_it = False
data_dir = None

elr_lor_converter = lor.fetch_elr_lor_converter(update, pickle_it, data_dir)

print(elr_lor_converter)
# {'ELR/LOR converter': <codes>,
#  'Last updated date': <date>}