Skip to main content

A small web scraper for collecting the railway codes used in the UK rail industry

Reason this release was yanked:

Obsolete

Project description

pyrcs

Author: Qian Fu Twitter URL

PyPI PyPI - Python Version GitHub GitHub code size in bytes PyPI - Downloads

A small web scraper for collecting railway codes and other data used in the UK rail industry.

Installation

pip install --upgrade pyrcs

Note:

  • Make sure you have the most up-to-date version of pip installed.

    python -m pip install --upgrade pip
    
  • Python-Levenshtein, one of the dependencies of this package, may fail to be installed on a Windows OS without VC2015 (or above). A workaround is to download and install its .whl file. In this case, you should go for python_Levenshtein-0.12.0-cp37-cp37m-win_amd64.whl if you're using Python 3.7 on 64-bit OS:

    pip install --upgrade \path\to\python_Levenshtein-0.12.0-cp37-cp37m-win_amd64.whl
    

Quick start (Examples)

The following examples may provide a quick guide to the usage of the package.

1. CRS, NLC, TIPLOC and STANOX Codes

If your preferred import style is from <module> import <name>:

from pyrcs.line_data_cls import crs_nlc_tiploc_stanox as ldlc

If your preferred import style is import <module>.<name>:

import pyrcs.line_data_cls.crs_nlc_tiploc_stanox as ldlc

After importing the module, you can create a 'class' for the location codes (including all CRS, NLC, TIPLOC, STANME and STANOX) :

location_codes = ldlc.LocationIdentifiers()

Given different preferences, there are several alternative ways of importing the module.

Alternative 1:

from pyrcs.line_data import crs_nlc_tiploc_stanox as ldlc
location_codes = ldlc.LocationIdentifiers()

Alternative 2 (Preferred and used for the following examples):

from pyrcs.line_data import LineData
line_data_cls = LineData()  # contains all classes under the category of 'Line data'
location_codes = line_data_cls.LocationIdentifiers

1.1 Locations beginning with a given letter

You can get the location codes starting with a specific letter, say 'A' or 'a', by using the methodcollect_location_codes_by_initial, which returns a dict.

# The input is case-insensitive
location_codes_a = location_codes.collect_location_codes_by_initial('A')

The keys of location_codes_a include:

  • 'A'
  • 'Last_updated_date'
  • 'Additional_note'

The corresponding values are:

  • location_codes_a['A'] is a pandas.DataFrame that contains the table data. You may compare it with the table on the web page: http://www.railwaycodes.org.uk/crs/CRSa.shtm
  • location_codes_a['Last_updated_date'] is the date (in str) when the web page was last updated
  • location_codes_a['Additional_note'] is some important additional information on the web page (if available)

1.2 All available location codes in this category

You can also get all available location codes in this category as a whole , using the method fetch_location_codes, which also returns a dict:

location_codes_data = location_codes.fetch_location_codes()

The keys of location_codes_a include:

  • 'Location_codes'
  • 'Latest_updated_date'
  • 'Additional_note'
  • 'Other_systems'

The corresponding values are:

  • location_codes_data['Location_codes'] is a pandas.DataFrame that contains all table data (from 'A' to 'Z')
  • location_codes_data['Latest_updated_date'] is the latest 'Last_updated_date' (in str) among all initial-specific table data
  • location_codes_data['Additional_note'] is some important additional information on the web page (if available)
  • location_codes_data['Other_systems'] is a dict for Other systems

2. Engineer's Line References (ELRs)

em = line_data_cls.ELRMileages

2.1 ELR codes

To get ELR codes starting with a specific letter, say 'A', by using the method collect_elr_by_initial, which returns a dict.

elr_a = em.collect_elr_by_initial('A')  # em.collect_elr_by_initial('a')

The keys of elr_a include:

  • 'A'
  • 'Last_updated_date'

The corresponding values are:

  • elr_a['A'] is a pandas.DataFrame that contains the table data. You may compare it with the table on the web page: http://www.railwaycodes.org.uk/elrs/elra.shtm
  • elr_a['Last_updated_date'] is the date (in str) when the web page was last updated

To get all available ELR codes, by using the method fetch_elr, which returns a dict:

elr_codes = em.fetch_elr()

The keys of elr_codes include:

  • 'ELRs_mileages'
  • 'Latest_updated_date'

The corresponding values are:

  • elr_codes['ELRs_mileages'] is a pandas.DataFrame that contains all table data (from 'A' to 'Z')
  • elr_codes['Latest_updated_date'] is the latest 'Last_updated_date' (in str) among all initial-specific table data

2.2 Mileage files

To collect more detailed mileage data for a given ELR, say 'AAM', by using the method fetch_mileage_file, which returns a dict:

em_amm = em.fetch_mileage_file('AAM')

The keys of em_amm include:

  • 'ELR'
  • 'Line'
  • 'Sub-Line'
  • 'AAM'

The corresponding values are:

  • em_amm['ELR'] is the name (in str) of the given ELR
  • em_amm['Line'] is associated line name (in str)
  • em_amm['Sub-Line'] is associated sub line name (in str), if available
  • em_amm['AAM'] is a pandas.DataFrame of the mileage file data

3. Railway stations data

The data of railway stations belongs to another category, 'Other assets'

from pyrcs.other_assets import OtherAssets
other_assets_cls = OtherAssets()

Similar to getting 'CRS, NLC, TIPLOC and STANOX Codes' above, to get stations data by a given initial letter (say 'A'):

stations_a = other_assets_cls.Stations.collect_station_locations('A')

To get all available stations data:

stations = other_assets_cls.Stations.fetch_station_locations()

The data type of both stations_a and stations are dict.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyrcs-0.2.3.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyrcs-0.2.3-py3-none-any.whl (1.8 MB view details)

Uploaded Python 3

File details

Details for the file pyrcs-0.2.3.tar.gz.

File metadata

  • Download URL: pyrcs-0.2.3.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for pyrcs-0.2.3.tar.gz
Algorithm Hash digest
SHA256 2f9b4231bb244304560d0fb0a859aef1b917714ea937948e3bd3e84806f68a8e
MD5 f1282474cd7700f834f81701b8b9ca3a
BLAKE2b-256 190650534c3f29452c0a607e08676743858c957db6d49e1efe0572b5772a5bc3

See more details on using hashes here.

File details

Details for the file pyrcs-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: pyrcs-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 1.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for pyrcs-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 476842ee6074a1868a0fbd5bd736c175b9ffef0626ff71d0af6f54b1fce3ed03
MD5 24b1f405c92e75a3d53d7575b96673ca
BLAKE2b-256 fa649cd6cb17aceca38b6f4e748c4a69315f4a3a6d5130f90675e82ebdd9243e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page