Skip to content

Commit

Permalink
updated with pyhelpers.validate_input_data_dir()
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeqfu committed Sep 8, 2020
1 parent bc9ec4d commit 9830695
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 54 deletions.
12 changes: 6 additions & 6 deletions pyrcs/line_data/crs_nlc_tiploc_stanox.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import more_itertools
import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.ops import confirmed
from pyhelpers.store import load_json, load_pickle, save, save_pickle

Expand Down Expand Up @@ -55,7 +55,7 @@ def __init__(self, data_dir=None, update=False):
self.Key = 'Location codes' # key to location codes
self.LUDKey = 'Last updated date' # key to last updated date
if data_dir:
self.DataDir = regulate_input_data_dir(data_dir)
self.DataDir = validate_input_data_dir(data_dir)
else:
self.DataDir = cd_dat("line-data", re.sub(r',| codes| and', '', self.Name.lower()).replace(" ", "-"))
self.CurrentDataDir = copy.copy(self.DataDir)
Expand Down Expand Up @@ -268,7 +268,7 @@ def fetch_multiple_station_codes_explanatory_note(self, update=False, pickle_it=

if explanatory_note: # additional_note is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.MSCENPickle + ".pickle")
save_pickle(explanatory_note, path_to_pickle, verbose=True)
else:
Expand Down Expand Up @@ -373,7 +373,7 @@ def fetch_other_systems_codes(self, update=False, pickle_it=False, data_dir=None
verbose=False if data_dir or not verbose else True)
if other_systems_codes: # other_systems_codes is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.OSPickle + ".pickle")
save_pickle(other_systems_codes, path_to_pickle, verbose=True)
else:
Expand Down Expand Up @@ -584,7 +584,7 @@ def fetch_location_codes(self, update=False, pickle_it=False, data_dir=None, ver
self.LUDKey: latest_update_date}

if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.Key.lower().replace(" ", "-") + ".pickle")
save_pickle(location_codes, path_to_pickle, verbose=verbose)

Expand Down Expand Up @@ -673,7 +673,7 @@ def make_location_codes_dictionary(self, keys, initials=None, drop_duplicates=Fa
if main_key:
assert isinstance(main_key, str)

dat_dir = regulate_input_data_dir(data_dir) if data_dir else self.DataDir
dat_dir = validate_input_data_dir(data_dir) if data_dir else self.DataDir
path_to_file = os.path.join(dat_dir, "-".join(keys) +
("" if initials is None else "-" + "".join(initials)) +
(".json" if as_dict and len(keys) == 1 else ".pickle"))
Expand Down
14 changes: 7 additions & 7 deletions pyrcs/line_data/electrification.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import bs4
import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.ops import confirmed
from pyhelpers.store import load_pickle, save_pickle

Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, data_dir=None, update=False):
self.Date = get_last_updated_date(self.SourceURL, parsed=True, as_date_type=False)
self.Key = 'Electrification'
self.LUDKey = 'Last updated date' # key to last updated date
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", self.Key.lower())
self.DataDir = validate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", self.Key.lower())
self.CurrentDataDir = copy.copy(self.DataDir)
self.NationalNetworkKey = 'National network'
self.NationalNetworkPickle = self.NationalNetworkKey.lower().replace(" ", "-")
Expand Down Expand Up @@ -211,7 +211,7 @@ def fetch_codes_for_national_network(self, update=False, pickle_it=False, data_d

if national_network_ole: # codes_for_ole is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.NationalNetworkPickle + ".pickle")
save_pickle(national_network_ole, path_to_pickle, verbose=verbose)
else:
Expand Down Expand Up @@ -390,7 +390,7 @@ def fetch_codes_for_independent_lines(self, update=False, pickle_it=False, data_

if independent_lines_ole: # codes_for_independent_lines is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(independent_lines_ole, path_to_pickle, verbose=verbose)
else:
Expand Down Expand Up @@ -494,7 +494,7 @@ def fetch_codes_for_ohns(self, update=False, pickle_it=False, data_dir=None, ver

if ohns_codes: # ohns is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.OhnsPickle + ".pickle")
save_pickle(ohns_codes, path_to_pickle, verbose=verbose)
else:
Expand Down Expand Up @@ -627,7 +627,7 @@ def fetch_codes_for_energy_tariff_zones(self, update=False, pickle_it=False, dat

if etz_ole: # codes_for_energy_tariff_zones is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.TariffZonesPickle + ".pickle")
save_pickle(etz_ole, path_to_pickle, verbose=verbose)
else:
Expand Down Expand Up @@ -677,7 +677,7 @@ def fetch_electrification_codes(self, update=False, pickle_it=False, data_dir=No

if pickle_it and data_dir:
pickle_filename = self.Name.lower().replace(" ", "-") + ".pickle"
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(ole_section_codes, path_to_pickle, verbose=verbose)

Expand Down
8 changes: 4 additions & 4 deletions pyrcs/line_data/elrs_mileages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import numpy as np
import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.ops import confirmed
from pyhelpers.store import load_pickle, save_pickle
from pyhelpers.text import remove_punctuation
Expand Down Expand Up @@ -59,7 +59,7 @@ def __init__(self, data_dir=None, update=False):
self.Key = 'ELRs' # key to ELRs and mileages
self.LUDKey = 'Last updated date' # key to last updated date
if data_dir:
self.DataDir = regulate_input_data_dir(data_dir)
self.DataDir = validate_input_data_dir(data_dir)
else:
self.DataDir = cd_dat("line-data", self.Name.lower().replace(" ", "-"))
self.CurrentDataDir = copy.copy(self.DataDir)
Expand Down Expand Up @@ -395,7 +395,7 @@ def fetch_elr(self, update=False, pickle_it=False, data_dir=None, verbose=False)

if pickle_it and data_dir:
pickle_filename = self.Name.lower().replace(" ", "-") + ".pickle"
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(elrs_data, path_to_pickle, verbose=verbose)

Expand Down Expand Up @@ -684,7 +684,7 @@ def fetch_mileage_file(self, elr, update=False, pickle_it=False, data_dir=None,

if mileage_file:
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, os.path.basename(path_to_pickle))
save_pickle(mileage_file, path_to_pickle, verbose=verbose)
else:
Expand Down
6 changes: 3 additions & 3 deletions pyrcs/line_data/line_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.ops import confirmed
from pyhelpers.store import load_pickle, save_pickle

Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(self, data_dir=None, update=False):
self.Key = 'Line names'
self.LUDKey = 'Last updated date'
if data_dir:
self.DataDir = regulate_input_data_dir(data_dir)
self.DataDir = validate_input_data_dir(data_dir)
else:
self.DataDir = cd_dat("line-data", self.Key.lower().replace(" ", "-"))
self.CurrentDataDir = copy.copy(self.DataDir)
Expand Down Expand Up @@ -194,7 +194,7 @@ def fetch_line_names(self, update=False, pickle_it=False, data_dir=None, verbose
verbose=False if data_dir or not verbose else True)
if line_names_data: # line-names is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(line_names_data, path_to_pickle, verbose=verbose)
else:
Expand Down
8 changes: 4 additions & 4 deletions pyrcs/line_data/lor_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import bs4
import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.ops import confirmed
from pyhelpers.store import load_pickle, save_pickle

Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(self, data_dir=None, update=False):
self.Date = get_last_updated_date(self.SourceURL, parsed=True, as_date_type=False)
self.Key = 'LOR'
self.LUDKey = 'Last updated date'
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", self.Key.lower())
self.DataDir = validate_input_data_dir(data_dir) if data_dir else cd_dat("line-data", self.Key.lower())
self.CurrentDataDir = copy.copy(self.DataDir)
self.PKey = 'Key to prefixes'
self.ELCKey = 'ELR/LOR converter'
Expand Down Expand Up @@ -348,7 +348,7 @@ def fetch_lor_codes(self, update=False, pickle_it=False, data_dir=None, verbose=

if pickle_it and data_dir:
pickle_filename = "lor-codes.pickle"
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(lor_codes_data, path_to_pickle, verbose=verbose)

Expand Down Expand Up @@ -466,7 +466,7 @@ def fetch_elr_lor_converter(self, update=False, pickle_it=False, data_dir=None,
verbose=False if data_dir or not verbose else True)
if elr_lor_converter: # codes_for_ole is not None
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(elr_lor_converter, path_to_pickle, verbose=verbose)
else:
Expand Down
6 changes: 3 additions & 3 deletions pyrcs/line_data/track_diagrams.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import bs4
import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.store import load_pickle, save_pickle

from pyrcs.utils import cd_dat, confirmed, fake_requests_headers, get_last_updated_date, get_track_diagrams_items, \
Expand Down Expand Up @@ -49,7 +49,7 @@ def __init__(self, data_dir=None, update=False):
self.Items = get_track_diagrams_items(self.SourceURL, self.Key, update=update)
self.Date = get_last_updated_date(self.SourceURL, parsed=True, as_date_type=False)
if data_dir:
self.DataDir = regulate_input_data_dir(data_dir)
self.DataDir = validate_input_data_dir(data_dir)
else:
self.DataDir = cd_dat("line-data", self.Key.lower().replace(" ", "-"))
self.CurrentDataDir = copy.copy(self.DataDir)
Expand Down Expand Up @@ -196,7 +196,7 @@ def fetch_sample_track_diagrams_catalogue(self, update=False, pickle_it=False, d
verbose=verbose_)
if track_diagrams_catalogue:
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, pickle_filename)
save_pickle(track_diagrams_catalogue, path_to_pickle, verbose=verbose)
else:
Expand Down
14 changes: 7 additions & 7 deletions pyrcs/other_assets/depots.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import bs4
import pandas as pd
import requests
from pyhelpers.dir import regulate_input_data_dir
from pyhelpers.dir import validate_input_data_dir
from pyhelpers.ops import confirmed
from pyhelpers.store import load_pickle, save_pickle

Expand Down Expand Up @@ -51,7 +51,7 @@ def __init__(self, data_dir=None, update=False):
self.Date = get_last_updated_date(self.SourceURL, parsed=True, as_date_type=False)
self.Key = 'Depots'
self.LUDKey = 'Last updated date' # key to last updated date
self.DataDir = regulate_input_data_dir(data_dir) if data_dir else cd_dat("other-assets", self.Key.lower())
self.DataDir = validate_input_data_dir(data_dir) if data_dir else cd_dat("other-assets", self.Key.lower())
self.CurrentDataDir = copy.copy(self.DataDir)
self.TCTKey, self.FDPTKey, self.S1950Key, self.GWRKey = list(self.Catalogue.keys())[1:]
self.TCTPickle = self.TCTKey.replace(" ", "-").lower()
Expand Down Expand Up @@ -175,7 +175,7 @@ def fetch_two_char_tops_codes(self, update=False, pickle_it=False, data_dir=None

if two_char_tops_codes_data:
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.TCTPickle + ".pickle")
save_pickle(two_char_tops_codes_data, path_to_pickle, verbose=verbose)
else:
Expand Down Expand Up @@ -293,7 +293,7 @@ def fetch_four_digit_pre_tops_codes(self, update=False, pickle_it=False, data_di

if four_digit_pretops_codes:
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, os.path.basename(path_to_pickle))
save_pickle(four_digit_pretops_codes, path_to_pickle, verbose=verbose)

Expand Down Expand Up @@ -399,7 +399,7 @@ def fetch_1950_system_codes(self, update=False, pickle_it=False, data_dir=None,

if system_1950_codes_data:
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, os.path.basename(path_to_pickle))
save_pickle(system_1950_codes_data, path_to_pickle, verbose=verbose)

Expand Down Expand Up @@ -518,7 +518,7 @@ def fetch_gwr_codes(self, update=False, pickle_it=False, data_dir=None, verbose=

if gwr_codes_data:
if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, os.path.basename(path_to_pickle))
save_pickle(gwr_codes_data, path_to_pickle, verbose=verbose)

Expand Down Expand Up @@ -568,7 +568,7 @@ def fetch_depot_codes(self, update=False, pickle_it=False, data_dir=None, verbos
self.LUDKey: self.Date}

if pickle_it and data_dir:
self.CurrentDataDir = regulate_input_data_dir(data_dir)
self.CurrentDataDir = validate_input_data_dir(data_dir)
path_to_pickle = os.path.join(self.CurrentDataDir, self.Key.lower() + ".pickle")
save_pickle(depot_codes, path_to_pickle, verbose=verbose)

Expand Down
Loading

0 comments on commit 9830695

Please sign in to comment.