LocationIdentifiers¶
A class for collecting CRS, NLC, TIPLOC and STANOX codes.
LocationIdentifiers.amendment_to_location_names_dict () |
Create a replacement dictionary for location name amendments. |
LocationIdentifiers.parse_additional_note_page (…) |
Parse addition note page. |
LocationIdentifiers.collect_multiple_station_codes_explanatory_note ([…]) |
Collect note about CRS code from source web page. |
LocationIdentifiers.fetch_multiple_station_codes_explanatory_note ([…]) |
Fetch multiple station codes explanatory note from local backup. |
LocationIdentifiers.collect_other_systems_codes ([…]) |
Collect data of the other systems codes from source web page. |
LocationIdentifiers.fetch_other_systems_codes ([…]) |
Fetch data of the other systems codes from local backup. |
LocationIdentifiers.collect_location_codes_by_initial (initial) |
Collect CRS, NLC, TIPLOC, STANME and STANOX codes for the given initial letter. |
LocationIdentifiers.fetch_location_codes ([…]) |
Fetch CRS, NLC, TIPLOC, STANME and STANOX codes from local backup. |
LocationIdentifiers.make_location_codes_dictionary (keys) |
Make a dict/dataframe for location code data for the given keys |
-
class
pyrcs.line_data.
LocationIdentifiers
(data_dir=None, update=False)[source]¶ A class for collecting CRS, NLC, TIPLOC and STANOX 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 LocationIdentifiers lid = LocationIdentifiers() print(lid.Name) # CRS, NLC, TIPLOC and STANOX codes print(lid.SourceURL) # http://www.railwaycodes.org.uk/crs/CRS0.shtm
-
static
amendment_to_location_names_dict
()[source]¶ Create a replacement dictionary for location name amendments.
Returns: dictionary of regular-expression amendments to location names Return type: str Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() location_name_amendment_dict = lid.amendment_to_location_names_dict()
-
static
parse_additional_note_page
(note_url, parser='lxml')[source]¶ Parse addition note page.
Parameters: - note_url (str) – URL link of the target web page
- parser (str) – the parser to use for bs4.BeautifulSoup, defaults to
'lxml'
Returns: parsed texts
Return type: list
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() note_url = locid.HomeURL + '/crs/CRS2.shtm' parser = 'lxml' parsed_note = lid.parse_additional_note_page(note_url, parser)
-
collect_multiple_station_codes_explanatory_note
(confirmation_required=True, verbose=False)[source]¶ Collect note about CRS code from source web page.
Parameters: - confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to
True
- verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to
False
Returns: data of multiple station codes explanatory note
Return type: dict, None
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() confirmation_required = True explanatory_note = lid.collect_multiple_station_codes_explanatory_note(confirmation_required) # To collect multiple station codes explanatory note? [No]|Yes: # >? yes print(explanatory_note) # {'Last updated date': <date>, # 'Multiple station codes explanatory note': <codes>, # 'Notes': <notes>}
- confirmation_required (bool) – whether to prompt a message for confirmation to proceed, defaults to
-
fetch_multiple_station_codes_explanatory_note
(update=False, pickle_it=False, data_dir=None, verbose=False)[source]¶ Fetch multiple station codes explanatory note 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: data of multiple station codes explanatory note
Return type: dict
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() update = False pickle_it = False data_dir = None verbose = True explanatory_note = lid.fetch_multiple_station_codes_explanatory_note(update, pickle_it, data_dir, verbose) print(explanatory_note) # {'Last updated date': <date>, # 'Multiple station codes explanatory note': <codes>, # 'Notes': <notes>}
- update (bool) – whether to check on update and proceed to update the package data, defaults to
-
collect_other_systems_codes
(confirmation_required=True, verbose=False)[source]¶ Collect data of the other systems codes from source web page.
Parameters: - confirmation_required (bool) – whether to require users to confirm and proceed, defaults to
True
- verbose (bool, int) – whether to print relevant information in console as the function runs, defaults to
False
Returns: codes of other systems
Return type: dict, None
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() confirmation_required = True verbose = True other_systems_codes = lid.collect_other_systems_codes(confirmation_required, verbose) # To collect additional CRS note? [No]|Yes: >? yes print(other_systems_codes) # {<system name>: <codes>, # ...}
- confirmation_required (bool) – whether to require users to confirm and proceed, defaults to
-
fetch_other_systems_codes
(update=False, pickle_it=False, data_dir=None, verbose=False)[source]¶ Fetch data of the other systems 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, int) – whether to print relevant information in console as the function runs, defaults to
False
Returns: codes of other systems
Return type: dict
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() update = False pickle_it = False data_dir = None verbose = True other_systems_codes = lid.fetch_other_systems_codes(update, pickle_it, data_dir, verbose)
- update (bool) – whether to check on update and proceed to update the package data, defaults to
-
collect_location_codes_by_initial
(initial, update=False, verbose=False)[source]¶ Collect CRS, NLC, TIPLOC, STANME and STANOX codes for the given
initial
letter.Parameters: - initial (str) – initial letter of station/junction name or certain word for specifying URL
- 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: data of location codes for the given
initial
letter; and date of when the data was last updatedReturn type: dict
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() initial = 'a' location_codes_a = lid.collect_location_codes_by_initial(initial) print(location_codes_a) # {'A': <codes>, # 'Additional notes': <notes>, # 'Last updated date': <date>}
-
fetch_location_codes
(update=False, pickle_it=False, data_dir=None, verbose=False)[source]¶ Fetch CRS, NLC, TIPLOC, STANME and STANOX 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, int) – whether to print relevant information in console as the function runs, defaults to
False
Returns: data of location codes and date of when the data was last updated
Return type: dict
Example:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() update = False pickle_it = False data_dir = None location_codes = lid.fetch_location_codes(update, pickle_it, data_dir) print(location_codes) # {'Location codes': <codes>, # 'Other systems': <codes>, # 'Additional notes': <notes>, # 'Latest update date': <date>}
- update (bool) – whether to check on update and proceed to update the package data, defaults to
-
make_location_codes_dictionary
(keys, initials=None, drop_duplicates=False, as_dict=False, main_key=None, save_it=False, data_dir=None, update=False, verbose=False)[source]¶ Make a dict/dataframe for location code data for the given
keys
Parameters: - keys (str, list) – one or a sublist of [‘CRS’, ‘NLC’, ‘TIPLOC’, ‘STANOX’, ‘STANME’]
- initials (str, list, None) – one or a sequence of initials for which the location codes are used, defaults to
None
- drop_duplicates (bool) – whether to drop duplicates, defaults to
False
- as_dict (bool) – whether to return a dictionary, defaults to
False
- main_key (str, None) – key of the returned dictionary if
as_dict
isTrue
, defaults toNone
- save_it (bool) – whether to save the location codes dictionary, defaults to
False
- data_dir (str, None) – name of package data folder, defaults to
None
- 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: dictionary or a data frame for location code data for the given
keys
Return type: dict, pandas.DataFrame, None
Examples:
from pyrcs.line_data import LocationIdentifiers lid = LocationIdentifiers() drop_duplicates = False save_it = False data_dir = None update = False keys = 'STANOX' initials = None as_dict = False main_key = None stanox_dictionary = lid.make_location_codes_dictionary(keys, initials, drop_duplicates, as_dict, main_key, save_it, data_dir, update) print(stanox_dictionary) keys = ['STANOX', 'TIPLOC'] initials = 'a' as_dict = False main_key = None stanox_dictionary = lid.make_location_codes_dictionary(keys, initials, drop_duplicates, as_dict, main_key, save_it, data_dir, update) print(stanox_dictionary) keys = ['STANOX', 'TIPLOC'] initials = 'b' as_dict = True main_key = 'Data' stanox_dictionary = lid.make_location_codes_dictionary(keys, initials, drop_duplicates, as_dict, main_key, save_it, data_dir, update) print(stanox_dictionary)
- data_dir (str, None) – name of data directory, defaults to