Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,20 @@ Jinja2 = ">=3.1.2"
weasyprint = ">=60.2"
lxml = ">=5.0.0"
xdg-base-dirs = "^6.0.1"
tomlkit = "^0.12.3"
tomlkit = "^0.13.0"

[tool.poetry.group.dev.dependencies]
black = ">=23.12.1"
black = {extras = ["d"], version = "^24.4.2"}
mypy = ">=1.8.0"

[tool.poetry.scripts]
amtrak-gtfs = "timetable_kit.amtrak.get_gtfs:main"
amtrak-stations = "timetable_kit.amtrak.json_stations:main"
via-gtfs = "timetable_kit.via.get_gtfs:main"
greyhound-gtfs = "timetable_kit.greyhound.get_gtfs:main"
hartford-line-gtfs = "timetable_kit.hartford_line.get_gtfs:main"
maple-leaf-gtfs = "timetable_kit.maple_leaf.get_gtfs:main"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion timetable_kit/amtrak/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
This has very similar code to baggage.py
"""

from io import StringIO # for parsing JSON
import json
from io import StringIO # for parsing JSON

import pandas as pd

Expand Down
6 changes: 1 addition & 5 deletions timetable_kit/amtrak/accessibility_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
Requires local bad_stations.csv file: That is generated by "json_stations.py process"
"""
import json
from pathlib import Path
from io import StringIO # Needed to parse JSON

import pandas as pd

# These are mine

from timetable_kit.file_locations import get_timetable_kit_data_home

from timetable_kit.amtrak.json_stations import (
load_stations_json,
load_station_details,
)

# To filter out that which is not a train station
from timetable_kit.amtrak.station_type import is_train_station
from timetable_kit.file_locations import get_timetable_kit_data_home

station_stats_dir = get_timetable_kit_data_home() / "amtrak" / "station_stats"
stations_csv_path = get_timetable_kit_data_home() / "amtrak" / "stations.csv"
Expand Down
30 changes: 12 additions & 18 deletions timetable_kit/amtrak/agency.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,33 @@

This holds a class for "AgencyAmtrak" intended to be used as a singleton.
"""
from timetable_kit.feed_enhanced import FeedEnhanced # Mostly for typechecking

from timetable_kit.generic_agency import Agency

# for patch_feed
import timetable_kit.amtrak.gtfs_patches as gtfs_patches

# for patch_add_wheelchair_boarding
import timetable_kit.amtrak.access as access

# for sleeper trains, which trains have checked baggage, major stations, etc
import timetable_kit.amtrak.special_data as special_data

# for whether stations have checked baggage
import timetable_kit.amtrak.baggage as baggage

# for patch_feed
import timetable_kit.amtrak.gtfs_patches as gtfs_patches

# for get_station_name
import timetable_kit.amtrak.json_stations as json_stations

# for get_route_name
import timetable_kit.amtrak.route_names as route_names

# for sleeper trains, which trains have checked baggage, major stations, etc
import timetable_kit.amtrak.special_data as special_data

# for get_station_name_pretty (subroutines)
import timetable_kit.text_assembly as text_assembly
from timetable_kit.text_assembly import SAFE_BR

# Map from station codes to connecting service names
# This is stashed in a class variable
from timetable_kit.amtrak.connecting_services_data import connecting_services_dict

# for get_route_name
import timetable_kit.amtrak.route_names as route_names
from timetable_kit.feed_enhanced import FeedEnhanced # Mostly for typechecking
from timetable_kit.generic_agency import Agency
from timetable_kit.text_assembly import SAFE_BR


class AgencyAmtrak(Agency):
Expand Down Expand Up @@ -109,10 +107,6 @@ def connecting_bus_key_sentence(self, doing_html=True) -> str:
"""Sentence to put in the symbol key for connecting bus services."""
return "Connecting Bus Service (can be booked through Amtrak)"

def agency_css_class(self) -> str:
"""Name of a CSS class for agency-specific styling."""
return "amtrak-special-css"

def get_route_name(self, today_feed: FeedEnhanced, route_id: str) -> str:
"""Given today_feed and a route_id, produce a suitalbe name for a column
subheading.
Expand Down
6 changes: 3 additions & 3 deletions timetable_kit/amtrak/agency_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def revised_amtrak_agencies(agency):
)
# Edit the lookup table:
# This was only needed for pre-2022 Amtrak data.
agency_lookup_table[
174
] = "Amtrak Directly Operated Thruway Bus" # Is "Amtrak" in feed
agency_lookup_table[174] = (
"Amtrak Directly Operated Thruway Bus" # Is "Amtrak" in feed
)
agency_lookup_table[192] = "Thruway Bus Operator 192"
agency_lookup_table[1206] = "Thruway Bus Operator 1206"
agency_lookup_table[1207] = "Thruway Bus Operator 1207"
Expand Down
2 changes: 1 addition & 1 deletion timetable_kit/amtrak/baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
Requires local copy of Amtrak stations database: That local copy is generated by "json_stations.py download"
"""

from io import StringIO # for parsing JSON
import json
from io import StringIO # for parsing JSON

import pandas as pd

Expand Down
6 changes: 5 additions & 1 deletion timetable_kit/amtrak/get_gtfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def get_gtfs_files():
return _gtfs_files


def main():
get_gtfs_files().download_and_save()


# MAIN PROGRAM
if __name__ == "__main__":
get_gtfs_files().download_and_save()
main()
3 changes: 1 addition & 2 deletions timetable_kit/amtrak/get_wiki_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
"""

import argparse
from pathlib import Path
import re
from math import nan
from pathlib import Path

import pandas as pd


arg_parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""Process the list of Amtrak stations in Wikipedia.
Expand Down
13 changes: 6 additions & 7 deletions timetable_kit/amtrak/gtfs_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
"""
# TODO: all the Amtrak-specific stuff needs to be made object oriented in an "Amtrak object" perhaps

from timetable_kit.debug import debug_print
from timetable_kit.feed_enhanced import FeedEnhanced

# Add the wheelchair boarding information from JSON into the GTFS
from timetable_kit.amtrak.access import patch_add_wheelchair_boarding
from timetable_kit.debug import debug_print
from timetable_kit.feed_enhanced import FeedEnhanced

arizona_stops_list = [
# Sunset Limited
Expand Down Expand Up @@ -116,7 +115,7 @@ def patch_hiawatha(feed: FeedEnhanced):


def patch_sunset_limited(feed: FeedEnhanced):
"""Patch a bug where Sunset Limited #2 has wrong departure days.
"""Patch a bug where Sunset Limited #2 has wrong departure days.
It departs from LAX on Su/We/Fr and not Sa/Tu/Th

The bug is because it starts so late it starts on the following day in Eastern Standard Time.
Expand All @@ -139,17 +138,17 @@ def patch_sunset_limited(feed: FeedEnhanced):
debug_print(1, "Found #2 listed as running on Saturday, patching")
new_calendar.loc[index, "sunday"] = 0
new_calendar.loc[index, "monday"] = 1
#feed.calendar = new_calendar
# feed.calendar = new_calendar
if new_calendar.loc[index, "wednesday"] == 1: # This is incorrrect.
debug_print(1, "Found #2 listed as running on Tuesday, patching")
new_calendar.loc[index, "wednesday"] = 0
new_calendar.loc[index, "thursday"] = 1
#feed.calendar = new_calendar
# feed.calendar = new_calendar
if new_calendar.loc[index, "friday"] == 1: # This is incorrrect.
debug_print(1, "Found #2 listed as running on Thursday, patching")
new_calendar.loc[index, "friday"] = 0
new_calendar.loc[index, "saturday"] = 1
#feed.calendar = new_calendar
# feed.calendar = new_calendar
feed.calendar = new_calendar


Expand Down
21 changes: 11 additions & 10 deletions timetable_kit/amtrak/json_stations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
# will download Amtrak's station files into the './stations/' directory
# otherwise runs test case

import sys
from pathlib import Path
from io import StringIO # Needed to parse JSON
import argparse

import requests
import json # better for the details import
import random
from io import StringIO # Needed to parse JSON
from pathlib import Path
from time import sleep # Avoid slamming Amtrak's server too fast -- not needed

import pandas as pd

import random
import requests

from timetable_kit.file_locations import get_timetable_kit_data_home

Expand Down Expand Up @@ -72,6 +68,7 @@ def download_stations_json() -> str:

def save_stations_json(stations_json: str):
"""Save Amtrak's basic stations database (json text) to a suitable file."""
stations_json_local_path().parent.mkdir(exist_ok=True)
with open(stations_json_local_path(), "w") as stations_json_local_file:
print(stations_json, file=stations_json_local_file)

Expand Down Expand Up @@ -448,8 +445,7 @@ def make_arg_parser():
return arg_parser


# MAIN PROGRAM
if __name__ == "__main__":
def main():
arg_parser = make_arg_parser()
args = arg_parser.parse_args()

Expand All @@ -463,3 +459,8 @@ def make_arg_parser():
download_one_station(str.upper(args.station_code))
case "process" | "p":
do_station_processing()


# MAIN PROGRAM
if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions timetable_kit/amtrak/station_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@

import sys # for sys.exit
from io import StringIO # Needed to parse JSON
import pandas as pd

# For parsing the HTML pages
import lxml.html
import pandas as pd

from timetable_kit.amtrak.json_stations import (
load_stations_json,
load_station_details_html,
)

# These are mine
from timetable_kit.debug import set_debug_level, debug_print
from timetable_kit.debug import set_debug_level

# This is a map from what we might see in the web page,
# to the key information in the form:
Expand Down
3 changes: 1 addition & 2 deletions timetable_kit/amtrak/wiki_station_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
get station names from Amtrak's JSON data.
"""

import pandas as pd
import gtfs_kit # type: ignore # Tell MyPy this has no type stubs

import pandas as pd

# Cities with multiple stations in the same city, requiring disambiguation
two_station_cities = [
Expand Down
3 changes: 2 additions & 1 deletion timetable_kit/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

# Mostly for agency defaulting
from timetable_kit import runtime_config
from timetable_kit.runtime_config import agency

# My packages: Local module imports
from timetable_kit.debug import set_debug_level
from timetable_kit.feed_enhanced import FeedEnhanced

# To initialize the feed -- does type changes
from timetable_kit.initialize import initialize_feed
from timetable_kit.runtime_config import agency

# Common arguments for the command line
from timetable_kit.timetable_argparse import (
Expand All @@ -28,6 +28,7 @@
add_debug_argument,
)


### "Compare" Debugging routines to check for changes in timetable


Expand Down
8 changes: 7 additions & 1 deletion timetable_kit/convenience_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
# Part of timetable_kit
# Copyright 2023 Nathanael Nerode. Licensed under GNU Affero GPL v.3 or later.
"""Types used for extra type-checking."""
from __future__ import annotations

# Do this after working our way through the codebase to fix all calls
# from typing import NewType

# Do this for now
from typing import TypeAlias, NewType, NamedTuple
from typing import TypeAlias, NamedTuple

from pandas import DataFrame, Series

# This must be a date in YYYYMMDD format
# type GTFSDate = NewType("GTFSDate", str)
Expand All @@ -28,3 +31,6 @@ class HtmlAndCss(NamedTuple):

html_text: str
css_text: str


Calendar = DataFrame | Series
Loading