Skip to content

Commit ac4354a

Browse files
authored
1.0.4.dev1 (Scraper fixes, refactoring and docs updates) (#70)
1 parent c4a9e9b commit ac4354a

File tree

14 files changed

+138
-134
lines changed

14 files changed

+138
-134
lines changed

docs/source/conf.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,6 @@ def __init__(self, **options):
251251
),
252252
]
253253

254-
affil_dept, affil_univ = __affil__.split(', ')
255-
256254
# Custom title page:
257255
latex_maketitle = r'''
258256
\newgeometry{top=1.1in,bottom=1.1in,right=1.0in,left=1.0in}
@@ -270,10 +268,9 @@ def __init__(self, **options):
270268
\vspace{5mm}
271269
\LARGE \textbf{\textit{{Release %s}}} \par
272270
273-
\vspace{45mm}
271+
\vspace{50mm}
274272
\LARGE \textbf{{%s}} \par
275273
\Large \textit{{%s}} \par
276-
\Large \textit{{%s}} \par
277274
278275
\vspace{50mm}
279276
\Large {{First release:}} \large \textbf{{%s}} \par
@@ -303,8 +300,7 @@ def __init__(self, **options):
303300
__desc__.replace('different UK', 'different \\newline UK'),
304301
__version__,
305302
__author__,
306-
affil_dept,
307-
affil_univ,
303+
__affil__,
308304
__first_release__,
309305
__copyright__)
310306

docs/source/quick-start.rst

Lines changed: 83 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ A snapshot of the data contained in ``loc_a_codes`` is demonstrated below:
9292
3 A483 Road Scheme Supervisors Closed ...
9393
4 Aachen ...
9494
... ... .. ... ... ...
95-
3319 Ayr Wagon Team ...
96-
3320 Ayr Wagon Team ...
97-
3321 Ayr Wagon Team ...
98-
3322 Ayr Welders ...
99-
3323 Aztec Travel S378 ...
100-
[3324 rows x 12 columns]
95+
3322 Ayr Wagon Team ...
96+
3323 Ayr Wagon Team ...
97+
3324 Ayr Wagon Team ...
98+
3325 Ayr Welders ...
99+
3326 Aztec Travel S378 ...
100+
[3327 rows x 12 columns]
101101
>>> print(f"Notes: {loc_a_codes['Notes']}")
102102
>>> print(f"Last updated date: {loc_a_codes['Last updated date']}")
103103
Notes: None
104-
Last updated date: 2025-06-04
104+
Last updated date: 2025-12-11
105105
106106
>>> ## Try more examples! Uncomment the lines below and run:
107107
>>> # loc_a_codes = lid.fetch_loc_id('a') # Fetch location codes starting with 'A'
@@ -153,12 +153,12 @@ Here is a snapshot of the data contained in ``loc_codes``:
153153
3 A483 Road Scheme Supervisors Closed ...
154154
4 Aachen ...
155155
... ... .. ... ... ...
156-
59949 ZZTYALS ...
157-
59950 ZZTYKKH ...
158-
59951 ZZTYLIN ...
159-
59952 ZZTYSGY ...
160-
59953 ZZWMNST ...
161-
[59954 rows x 12 columns]
156+
60023 ZZTYALS ...
157+
60024 ZZTYKKH ...
158+
60025 ZZTYLIN ...
159+
60026 ZZTYSGY ...
160+
60027 ZZWMNST ...
161+
[60028 rows x 12 columns]
162162
>>> loc_codes_dat[['Location', 'Location_Note']]
163163
Location Location_Note
164164
0 1999 Reorganisations
@@ -167,12 +167,12 @@ Here is a snapshot of the data contained in ``loc_codes``:
167167
3 A483 Road Scheme Supervisors Closed
168168
4 Aachen
169169
... ... ...
170-
59949 ZZTYALS see Alston
171-
59950 ZZTYKKH see Kirkhaugh
172-
59951 ZZTYLIN see Lintley
173-
59952 ZZTYSGY see Slaggyford
174-
59953 ZZWMNST see Westminster
175-
[59954 rows x 2 columns]
170+
60023 ZZTYALS see Alston
171+
60024 ZZTYKKH see Kirkhaugh
172+
60025 ZZTYLIN see Lintley
173+
60026 ZZTYSGY see Slaggyford
174+
60027 ZZWMNST see Westminster
175+
[60028 rows x 2 columns]
176176
177177
To access codes from other systems, such as Crossrail or the Tyne & Wear Metro:
178178

@@ -182,7 +182,7 @@ To access codes from other systems, such as Crossrail or the Tyne & Wear Metro:
182182
'Other systems'
183183
>>> os_codes_dat = loc_codes[lid.KEY_TO_OTHER_SYSTEMS]
184184
>>> type(os_codes_dat)
185-
collections.defaultdict
185+
dict
186186
>>> list(os_codes_dat.keys())
187187
['Córas Iompair Éireann (Republic of Ireland)',
188188
'Crossrail',
@@ -200,13 +200,19 @@ For example, to view the data for Crossrail:
200200
>>> type(crossrail_codes_dat)
201201
pandas.core.frame.DataFrame
202202
>>> crossrail_codes_dat.head()
203-
Location ... New operating code
204-
0 Abbey Wood ... ABW
205-
1 Abbey Wood Bolthole Berth/Crossrail Sidings ...
206-
2 Abbey Wood Sidings ...
207-
3 Bond Street ... BDS
208-
4 Canary Wharf ... CWX
209-
[5 rows x 5 columns]
203+
Location ... New operating code
204+
0 Abbey Wood ... ABW
205+
1 Abbey Wood Bolthole Berth/Crossrail Sidings ...
206+
2 Abbey Wood Sidings ...
207+
3 Bond Street ... BDS
208+
4 Canary Wharf ... CWX
209+
... ... ... ...
210+
26 Whitechapel ... ZLW
211+
27 Whitechapel Vallance Road Crossover ...
212+
28 Woolwich ... WWC
213+
29 [unknown] ...
214+
30 [unknown] ...
215+
[31 rows x 5 columns]
210216
211217
>>> ## Try more examples! Uncomment the lines below and run:
212218
>>> ## Get a dictionary for STANOX codes and location names
@@ -320,12 +326,12 @@ Here is a snapshot of the data contained in ``elrs_codes``:
320326
3 ABB ... Now AHB
321327
4 ABB ...
322328
... ... ... ...
323-
4570 ZGW1 ...
324-
4571 ZGW2 ...
325-
4572 ZZY ...
326-
4573 ZZZ ...
327-
4574 ZZZ9 ...
328-
[4575 rows x 5 columns]
329+
4573 ZGW1 ...
330+
4574 ZGW2 ...
331+
4575 ZZY ...
332+
4576 ZZZ ...
333+
4577 ZZZ9 ...
334+
[4578 rows x 5 columns]
329335
330336
>>> ## Try more examples! Uncomment the lines below and run:
331337
>>> # elrs_a_codes = em.fetch_elr(initial='a') # Fetch ELRs starting with 'A'
@@ -458,25 +464,25 @@ Here is a snapshot of the data contained in ``stn_loc_a``:
458464
>>> type(stn_loc_a_codes_dat)
459465
pandas.core.frame.DataFrame
460466
>>> stn_loc_a_codes_dat
461-
Station ... Former Operator
462-
0 Abbey Wood Abbey Wood / ABBEY WOOD ... London & South Eastern Rai...
463-
1 Abbey Wood Abbey Wood / ABBEY WOOD ... London & South Eastern Rai...
464-
2 Aber ... Keolis Amey Operations/Gwe...
465-
3 Abercynon ... Keolis Amey Operations/Gwe...
466-
4 Abercynon ... Keolis Amey Operations/Gwe...
467-
.. ... ... ...
468-
137 Aylesbury Vale Parkway ...
469-
138 Aylesford ... London & South Eastern Rai...
470-
139 Aylesham ... London & South Eastern Rai...
471-
140 Ayr ... Abellio ScotRail from 1 Ap...
472-
141 Ayr ... Abellio ScotRail from 1 Ap...
473-
[142 rows x 14 columns]
467+
Station ... Former Operator
468+
0 Abbey Wood Abbey Wood / ABBEY WOOD ... MTR Corporation (Crossrail)...
469+
1 Abbey Wood Abbey Wood / ABBEY WOOD ... MTR Corporation (Crossrail)...
470+
2 Aber ... Keolis Amey Operations/Gwei...
471+
3 Abercynon ... Keolis Amey Operations/Gwei...
472+
4 Abercynon ... Keolis Amey Operations/Gwei...
473+
.. ... ... ...
474+
138 Aylesbury Vale Parkway ...
475+
139 Aylesford ... London & South Eastern Rail...
476+
140 Aylesham ... London & South Eastern Rail...
477+
141 Ayr ... Abellio ScotRail from 1 Apr...
478+
142 Ayr ... Abellio ScotRail from 1 Apr...
479+
[143 rows x 14 columns]
474480
>>> stn_loc_a_codes_dat.columns.to_list()
475481
['Station',
476482
'Station Note',
477483
'ELR',
478484
'Mileage',
479-
'Status',
485+
'Note',
480486
'Degrees Longitude',
481487
'Degrees Latitude',
482488
'Grid Reference',
@@ -494,14 +500,14 @@ Here is a snapshot of the data contained in ``stn_loc_a``:
494500
3 Abercynon CAM 16m 28ch
495501
4 Abercynon ABD 16m 28ch
496502
.. ... ... ...
497-
137 Aylesbury Vale Parkway MCJ2 40m 38ch
498-
138 Aylesford PWS2 38m 74ch
499-
139 Aylesham FDM 68m 66ch
500-
140 Ayr AYR6 40m 49ch
501-
141 Ayr STR1 40m 49ch
502-
[142 rows x 3 columns]
503+
138 Aylesbury Vale Parkway MCJ2 40m 38ch
504+
139 Aylesford PWS2 38m 74ch
505+
140 Aylesham FDM 68m 66ch
506+
141 Ayr AYR6 40m 49ch
507+
142 Ayr STR1 40m 49ch
508+
[143 rows x 3 columns]
503509
>>> print(f"Last updated date: {stn_loc_a_codes['Last updated date']}")
504-
Last updated date: 2025-06-16
510+
Last updated date: 2025-12-17
505511
506512
.. _quickstart-all-available-railway-stations:
507513

@@ -538,29 +544,30 @@ Here is a snapshot of the data contained in ``stn_loc_codes``:
538544
>>> type(stn_loc_codes_dat)
539545
pandas.core.frame.DataFrame
540546
>>> stn_loc_codes_dat
541-
Station ... Former Operator
542-
0 Abbey Wood Abbey Wood / ABBEY WOOD ... London & South Eastern Ra...
543-
1 Abbey Wood Abbey Wood / ABBEY WOOD ... London & South Eastern Ra...
544-
2 Aber ... Keolis Amey Operations/Gw...
545-
3 Abercynon ... Keolis Amey Operations/Gw...
546-
4 Abercynon ... Keolis Amey Operations/Gw...
547-
... ... ... ...
548-
2901 York ... East Coast Main Line Comp...
549-
2902 York ... East Coast Main Line Comp...
550-
2903 Yorton ... Keolis Amey Operations/Gw...
551-
2904 Ystrad Mynach ... Keolis Amey Operations/Gw...
552-
2905 Ystrad Rhondda ... Keolis Amey Operations/Gw...
553-
[2906 rows x 14 columns]
554-
>>> sel_cols = ['Station', 'ELR', 'Mileage', 'Degrees Longitude', 'Degrees Latitude']
555-
>>> stn_loc_codes_dat[sel_cols].tail()
556-
Station ELR Mileage Degrees Longitude Degrees Latitude
557-
2901 York ECM5 0m 00ch -1.0920 53.9584
558-
2902 York ECM4 188m 40ch -1.0920 53.9584
559-
2903 Yorton SYC 25m 14ch -2.7360 52.8083
560-
2904 Ystrad Mynach CAR 13m 60ch -3.2414 51.6414
561-
2905 Ystrad Rhondda THT 20m 05ch -3.4666 51.6436
547+
Station ... Former Operator
548+
0 Abbey Wood Abbey Wood / ABBEY WOOD ... MTR Corporation (Crossrail)...
549+
1 Abbey Wood Abbey Wood / ABBEY WOOD ... MTR Corporation (Crossrail)...
550+
2 Aber ... Keolis Amey Operations/Gwei...
551+
3 Abercynon ... Keolis Amey Operations/Gwei...
552+
4 Abercynon ... Keolis Amey Operations/Gwei...
553+
... ... ... ...
554+
2912 York ... East Coast Main Line Compa...
555+
2913 York ... East Coast Main Line Compa...
556+
2914 Yorton ... Keolis Amey Operations/Gwe...
557+
2915 Ystrad Mynach ... Keolis Amey Operations/Gwe...
558+
2916 Ystrad Rhondda ... Keolis Amey Operations/Gwe...
559+
[2917 rows x 14 columns]
560+
>>> loc_cols = ['Station', 'ELR', 'Mileage', 'Degrees Longitude', 'Degrees Latitude']
561+
>>> stn_loc_codes_dat[loc_cols].head()
562+
Station ELR ... Degrees Longitude Degrees Latitude
563+
0 Abbey Wood Abbey Wood / ABBEY WOOD NKL ... 0.1204 51.4908
564+
1 Abbey Wood Abbey Wood / ABBEY WOOD XRS ... 0.1204 51.4908
565+
2 Aber CAR ... -3.2305 51.5755
566+
3 Abercynon CAM ... -3.3294 51.6434
567+
4 Abercynon ABD ... -3.3294 51.6434
568+
[5 rows x 5 columns]
562569
>>> print(f"Last updated date: {stn_loc_codes['Last updated date']}")
563-
Last updated date: 2025-07-03
570+
Last updated date: 2025-12-23
564571
565572
>>> ## Try more examples! Uncomment the lines below and run:
566573
>>> # stn_loc_a_codes = em.fetch_locations('a') # railway stations starting with 'A'

docs/source/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
furo==2025.9.25
2-
pyhelpers==2.3.1
1+
furo==2025.12.19
2+
pyhelpers==2.3.2
33
sphinx-copybutton==0.5.2
44
sphinx-new-tab-link==0.8.1
55
sphinx-toggleprompt==0.6.0

pyrcs/_base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,9 @@ def _collect_data_from_source(self, data_name, method, url=None, initial=None,
273273
if not url_:
274274
if initial and verbose:
275275
print(f'No data is available for codes beginning with "{initial}".')
276+
elif data_name and not url:
277+
print('Key not found in `.catalogue`. '
278+
'Check `.catalogue` for valid keys, and verify `initial` or `data_name`.')
276279
return fallback_data
277280

278281
try:

pyrcs/data/.metadata

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
"Description": "An open-source tool for collecting railway codes used in different UK rail industry systems",
44
"Package": "pyrcs",
55
"Author": "Qian Fu",
6-
"Affiliation": "School of Engineering, University of Birmingham",
6+
"Affiliation": "University of Birmingham",
77
"Email": "q.fu@bham.ac.uk",
8-
"Version": "1.0.3",
8+
"Version": "1.0.4.dev1",
99
"License": "MIT",
1010
"First release": "August 2019"
1111
}

pyrcs/data/site-map.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"pride/pride1": "http://www.railwaycodes.org.uk/pride/pride1.shtm",
8484
"pride/pridecy": "http://www.railwaycodes.org.uk/pride/pridecy.shtm",
8585
"pride/prideea": "http://www.railwaycodes.org.uk/pride/prideea.shtm",
86+
"pride/prideex": "http://www.railwaycodes.org.uk/pride/prideex.shtm",
8687
"pride/pridegw": "http://www.railwaycodes.org.uk/pride/pridegw.shtm",
8788
"pride/prideln": "http://www.railwaycodes.org.uk/pride/prideln.shtm",
8889
"pride/pridemd": "http://www.railwaycodes.org.uk/pride/pridemd.shtm",

pyrcs/line_data/loc_id.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,7 +900,7 @@ def _collect_other_systems_codes(self, source, verbose=False):
900900
other_systems_codes.update({h3.text: self._parse_tbl_dat(h3)})
901901

902902
other_systems_codes = {
903-
self.KEY_TO_OTHER_SYSTEMS: other_systems_codes,
903+
self.KEY_TO_OTHER_SYSTEMS: dict(other_systems_codes),
904904
self.KEY_TO_LAST_UPDATED_DATE: _get_last_updated_date(soup=soup),
905905
}
906906

@@ -947,7 +947,7 @@ def collect_other_systems_codes(self, confirmation_required=True, verbose=False,
947947
'Other systems'
948948
>>> os_codes_dat = os_codes[lid.KEY_TO_OTHER_SYSTEMS]
949949
>>> type(os_codes_dat)
950-
collections.defaultdict
950+
dict
951951
>>> list(os_codes_dat.keys())
952952
['Córas Iompair Éireann (Republic of Ireland)',
953953
'Crossrail',

pyrcs/other_assets/depot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class Depots(_Base):
2626
KEY: str = 'Depots'
2727

2828
#: The key for accessing the data of two character TOPS codes
29-
KEY_TO_TOPS: str = 'Two character TOPS codes'
29+
KEY_TO_TOPS: str = 'Two character TOPS'
3030
#: The key for accessing the data of four digit pre-TOPS codes
31-
KEY_TO_PRE_TOPS: str = 'Four digit pre-TOPS codes'
31+
KEY_TO_PRE_TOPS: str = 'Four digit pre-TOPS'
3232
#: The key for accessing the data of 1950 system (pre-TOPS) codes
33-
KEY_TO_1950_SYSTEM: str = '1950 system (pre-TOPS) codes'
33+
KEY_TO_1950_SYSTEM: str = '1950 system (pre-TOPS)'
3434
#: The key for accessing the data of GWR codes
35-
KEY_TO_GWR: str = 'GWR codes'
35+
KEY_TO_GWR: str = 'GWR'
3636

3737
#: The URL of the main web page for the data.
3838
URL: str = urllib.parse.urljoin(home_page_url(), '/depots/depots0.shtm')

pyrcs/other_assets/sig_box.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ def _collect_wr_mas_dates(self, source, verbose=False):
605605
wr_mas_dates.update({h3.text: self._parse_tbl_dat(h3, ths)})
606606

607607
wr_mas_dates_data = {
608-
self.KEY_TO_WRMASD: wr_mas_dates,
608+
self.KEY_TO_WRMASD: dict(wr_mas_dates),
609609
self.KEY_TO_LAST_UPDATED_DATE: _get_last_updated_date(soup),
610610
}
611611

@@ -651,8 +651,8 @@ def collect_wr_mas_dates(self, confirmation_required=True, verbose=False, raise_
651651
'WR MAS dates'
652652
>>> sb_wr_mas_dates_dat = sb_wr_mas_dates[sb.KEY_TO_WRMASD]
653653
>>> type(sb_wr_mas_dates_dat)
654-
collections.defaultdict
655-
>>> list(sb_wr_mas_dates_dat.keys())
654+
dict
655+
>>> list(sb_wr_mas_dates_dat.keys())[:5]
656656
['Paddington-Hayes',
657657
'Birmingham',
658658
'Plymouth',
@@ -702,7 +702,7 @@ def fetch_wr_mas_dates(self, update=False, dump_dir=None, verbose=False, **kwarg
702702
'WR MAS dates'
703703
>>> sb_wr_mas_dates_dat = sb_wr_mas_dates[sb.KEY_TO_WRMASD]
704704
>>> type(sb_wr_mas_dates_dat)
705-
collections.defaultdict
705+
dict
706706
>>> list(sb_wr_mas_dates_dat.keys())[:5]
707707
['Paddington-Hayes',
708708
'Birmingham',
@@ -782,7 +782,7 @@ def collect_bell_codes(self, confirmation_required=True, verbose=False, raise_er
782782
'Bell codes'
783783
>>> sb_bell_codes_dat = sb_bell_codes[sb.KEY_TO_BELL_CODES]
784784
>>> type(sb_bell_codes_dat)
785-
collections.OrderedDict
785+
dict
786786
>>> list(sb_bell_codes_dat.keys())
787787
['Network Rail codes',
788788
'Southern Railway codes',
@@ -840,7 +840,7 @@ def fetch_bell_codes(self, update=False, dump_dir=None, verbose=False, **kwargs)
840840
'Bell codes'
841841
>>> sb_bell_codes_dat = sb_bell_codes[sb.KEY_TO_BELL_CODES]
842842
>>> type(sb_bell_codes_dat)
843-
collections.OrderedDict
843+
dict
844844
>>> list(sb_bell_codes_dat.keys())
845845
['Network Rail codes',
846846
'Southern Railway codes',

0 commit comments

Comments
 (0)