-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
gatelogue-aggregator/src/gatelogue_aggregator/sources/sea/hbl.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import re | ||
from pathlib import Path | ||
|
||
import rich | ||
|
||
from gatelogue_aggregator.downloader import DEFAULT_CACHE_DIR, DEFAULT_TIMEOUT | ||
from gatelogue_aggregator.logging import RESULT | ||
from gatelogue_aggregator.sources.wiki_base import get_wiki_html | ||
from gatelogue_aggregator.types.base import Source | ||
from gatelogue_aggregator.types.node.sea import SeaSource, SeaContext, SeaLineBuilder | ||
|
||
|
||
class HBL(SeaSource): | ||
name = "MRT Wiki (Sea, Hummingbird Boat Lines)" | ||
priority = 0 | ||
|
||
def __init__(self, cache_dir: Path = DEFAULT_CACHE_DIR, timeout: int = DEFAULT_TIMEOUT): | ||
SeaContext.__init__(self) | ||
Source.__init__(self) | ||
|
||
company = self.sea_company(name="Hummingbird Boat Lines") | ||
|
||
html = get_wiki_html("Hummingbird Boat Lines", cache_dir, timeout) | ||
for td in html.find("table", class_="multicol").find_all("td"): | ||
for p, ul in zip(td.find_all("p"), td.find_all("ul"), strict=False): | ||
line_code = str(p.span.string or p.span.span.string).strip() | ||
line_name = str(p.b.string).strip() | ||
line_colour = re.match(r"background-color:\s*([^;]*)", p.span.attrs["style"]).group(1) | ||
line = self.sea_line(code=line_code, company=company, name=line_name, colour=line_colour) | ||
|
||
stops = [] | ||
for li in ul.find_all("li"): | ||
if "Planned" in li.strings: | ||
continue | ||
stop_name = "".join(li.strings) | ||
stop = self.sea_stop(codes={stop_name}, name=stop_name, company=company) | ||
stops.append(stop) | ||
|
||
if len(stops) == 0: | ||
continue | ||
|
||
SeaLineBuilder(self, line).matrix(*stops) | ||
|
||
rich.print(RESULT + f"HBL Line {line_code} has {len(stops)} stops") |
162 changes: 162 additions & 0 deletions
162
gatelogue-aggregator/src/gatelogue_aggregator/sources/sea/hbl_warp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
import itertools | ||
import re | ||
import uuid | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
import rich | ||
|
||
from gatelogue_aggregator.downloader import DEFAULT_CACHE_DIR, DEFAULT_TIMEOUT, get_url, warps | ||
from gatelogue_aggregator.logging import ERROR | ||
from gatelogue_aggregator.types.base import Source | ||
from gatelogue_aggregator.types.node.sea import SeaContext, SeaSource | ||
|
||
# Adapted from https://docs.google.com/spreadsheets/d/1nIIettVbGwzm7DkmYqqPVoguw2U53R5un4nrC76w-Xg/edit#gid=1423194214 | ||
_DICT = { | ||
"ACH": "Achowalogen Takachsin", | ||
"ACR": "New Acreadium", | ||
"AIR": "Airchester", | ||
"ANT": "Anthro Island", | ||
"AQI": "Aquidneck Islands", | ||
"AXB": "Alexandriasburg", | ||
"BAK": "Bakersville", | ||
"BAY": "Bay Point", | ||
"BEA": "Beach City", | ||
"BIW": "Biwabik", | ||
"BVW": "Beachview", | ||
"CEL": "Celina", | ||
"CHG": "Chugsdy Island", | ||
"COV": "Covina", | ||
"CPC": "Cape Cambridge", | ||
"DEA": "Deadbush", | ||
"EDN": "Eden", | ||
"ELC": "Elecna Crescent", | ||
"ELE": "Elecna Bay", | ||
"ELF": "Ellerton Fosby", | ||
"EMS": "East Mesa", | ||
"ENB": "East New Brazil", | ||
"ENS": "Enspington", | ||
"FYX": "Fort Yaxier", | ||
"GAD": "Gorre & Daphetid", | ||
"GEN": "Geneva Bay", | ||
"GIL": "Gillmont", | ||
"GRY": "Gray Cloud", | ||
"HEA": "Heapstead", | ||
"HUM": "Hummingbird Islands", | ||
"ILI": "Ilirea", | ||
"INS": "Insula Montes", | ||
"IOC": "Isle of Chez", | ||
"ITK": "Itokani", | ||
"JIM": "Jimbo", | ||
"KAN": "Kanto", | ||
"KAP": "Kappen", | ||
"KAZ": "Kazeshima", | ||
"KEN": "Kenthurst", | ||
"KLE": "Kleinsburg", | ||
"LAC": "Lacklede", | ||
"LAP": "Lapis Bay", | ||
"LEG": "Lego City", | ||
"LEV": "Levittown", | ||
"LOS": "Los Angeles", | ||
"M10": "Mole Isle", | ||
"MAL": "Malosa", | ||
"MAR": "MRT Marina", | ||
"MAS": "Mason City", | ||
"MCK": "New Mackinaw", | ||
"MNI": "Monte Isola", | ||
"MOA": "Moramoa", | ||
"MOL": "Mole Island", | ||
"MOR": "Morihama", | ||
"MSL": "Marisol", | ||
"MTM": "Metamesa", | ||
"MUR": "Murrville", | ||
"NBK": "New Bakersville City", | ||
"NSG": "New Singapore", | ||
"ONE": "Onemalu", | ||
"OPA": "Oparia", | ||
"OTT": "Ottia Islands", | ||
"PIX": "Pixl", | ||
"PRA": "Praimina", | ||
"PSM": "Port Smith", | ||
"RIS": "Risima", | ||
"RIZ": "Rizalburg", | ||
"RJN": "Richard's Junction", | ||
"ROK": "Roke", | ||
"ROS": "New Rosemont", | ||
"RRI": "Railroad Isle", | ||
"SAN": "Sansmore", | ||
"SCH": "Schillerton", | ||
"SEA": "Seaview", | ||
"SEC": "Secunda", | ||
"SEH": "Seolho", | ||
"SEO": "Seoland", | ||
"SEU": "Seuland", | ||
"SHA": "Shahai", | ||
"SHN": "Shenghua", | ||
"SND": "Sand", | ||
"SOI": "Soiled Solitude", | ||
"SPL": "Spleef Island", | ||
"STA": "St. Anna", | ||
"STO": "Stoneedge", | ||
"SUN": "Sunshine Coast", | ||
"SVK": "Sansvikk", | ||
"SVZ": "San Vincenzo", | ||
"TIT": "Titsensaki", | ||
"TUL": "Tulipsburg", | ||
"TWE": "Tweebuffel", | ||
"VDM": "Verdantium", | ||
"VEN": "Ventura Harbor", | ||
"VER": "Vermilion", | ||
"VIC": "Victoria", | ||
"WAV": "Waverly", | ||
"WEN": "Wenyanga", | ||
"WEZ": "Weezerville", | ||
"WHI": "Whitechapel", | ||
"WHY": "Whiteley", | ||
"ZAQ": "Zaquar", | ||
} | ||
|
||
|
||
class HBLWarp(SeaSource): | ||
name = "MRT Warp API (Sea, Hummingbird Boat Lines)" | ||
priority = 1 | ||
|
||
def __init__(self, cache_dir: Path = DEFAULT_CACHE_DIR, timeout: int = DEFAULT_TIMEOUT): | ||
SeaContext.__init__(self) | ||
Source.__init__(self) | ||
|
||
company = self.sea_company(name="Hummingbird Boat Lines") | ||
|
||
names = list(_DICT.values()) | ||
for warp in itertools.chain( | ||
warps(uuid.UUID("c04532bc-45d7-4d89-a13f-1d3bb4b48f2a"), cache_dir, timeout), | ||
warps(uuid.UUID("8a928931-aa14-4a1c-8a39-0a7630922001"), cache_dir, timeout), | ||
): | ||
if (result := re.match(r"HBL_(...)_(.*)", warp["name"])) is None: | ||
continue | ||
if (name := _DICT.get(result.group(1))) is None: | ||
rich.print(ERROR + f"Unknown warp {warp['name']}") | ||
continue | ||
if name not in ("Covnia", "Kenthurst") and name not in names: | ||
continue | ||
if name == "Covina": | ||
if result.group(2) in ("1", "10"): | ||
name += " (marina)" | ||
elif result.group(2) in ("55", "57", "58"): | ||
name += " (canal)" | ||
elif name == "Kenthurst": | ||
if result.group(2) == "9": | ||
name += " (west)" | ||
elif result.group(2) in ("22", "24", "51", "55"): | ||
name += " (north)" | ||
|
||
self.sea_stop(codes={name}, company=company, name=name, world="New", coordinates=(warp["x"], warp["z"])) | ||
try: | ||
names.remove(name) | ||
except ValueError: | ||
pass | ||
|
||
names.remove("Covina") | ||
names.remove("Kenthurst") | ||
if names: | ||
rich.print(ERROR + f"Not found: {', '.join(names)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters