Skip to content

Commit

Permalink
refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
iiiii7d committed Jun 3, 2024
1 parent f900906 commit 6e213f0
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 26 deletions.
12 changes: 5 additions & 7 deletions gatelogue-aggregator/src/gatelogue_aggregator/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@

import click
import msgspec.json
import networkx as nx
import rich
import pygraphviz as pgv

from gatelogue_aggregator.__about__ import __version__
from gatelogue_aggregator.downloader import DEFAULT_CACHE_DIR, DEFAULT_TIMEOUT
from gatelogue_aggregator.sources.dynmap_airports import DynmapAirports
from gatelogue_aggregator.sources.mrt_transit import MRTTransit
from gatelogue_aggregator.sources.wiki_airline import WikiAirline
from gatelogue_aggregator.sources.wiki_airport import WikiAirport
from gatelogue_aggregator.sources.air.dynmap_airports import DynmapAirports
from gatelogue_aggregator.sources.air.mrt_transit import MRTTransit
from gatelogue_aggregator.sources.air.wiki_airline import WikiAirline
from gatelogue_aggregator.sources.air.wiki_airport import WikiAirport
from gatelogue_aggregator.types.context import Context


Expand Down Expand Up @@ -39,7 +37,7 @@ def run(*, cache_dir: Path, timeout: int, output: Path, fmt: bool, graph: Path |
WikiAirport(cache_dir, timeout),
]
)
if True or graph is not None:
if graph is not None:
ctx.graph(graph)
j = msgspec.json.encode(ctx.ser())
if fmt:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import rich.progress

from gatelogue_aggregator.downloader import DEFAULT_CACHE_DIR, DEFAULT_TIMEOUT
from gatelogue_aggregator.sources.air.wiki_extractors.airline import _EXTRACTORS
from gatelogue_aggregator.sources.wiki_base import get_wiki_link, get_wiki_text
from gatelogue_aggregator.sources.wiki_extractors.airline import _EXTRACTORS
from gatelogue_aggregator.types.air import AirContext, Airline, Airport, AirSource, Flight, Gate
from gatelogue_aggregator.types.base import Source, search_all
from gatelogue_aggregator.types.base import Source
from gatelogue_aggregator.utils import search_all

if TYPE_CHECKING:
from pathlib import Path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import rich.progress

from gatelogue_aggregator.downloader import DEFAULT_CACHE_DIR, DEFAULT_TIMEOUT
from gatelogue_aggregator.sources.air.wiki_extractors.airport import _EXTRACTORS
from gatelogue_aggregator.sources.wiki_base import get_wiki_link, get_wiki_text
from gatelogue_aggregator.sources.wiki_extractors.airport import _EXTRACTORS
from gatelogue_aggregator.types.air import AirContext, Airport, AirSource, Gate
from gatelogue_aggregator.types.base import Source, search_all
from gatelogue_aggregator.types.base import Source
from gatelogue_aggregator.utils import search_all

if TYPE_CHECKING:
from pathlib import Path
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from collections.abc import Callable
from pathlib import Path

from gatelogue_aggregator.sources.wiki_airline import WikiAirline
from gatelogue_aggregator.sources.air.wiki_airline import WikiAirline

_EXTRACTORS: list[Callable[[WikiAirline, Path, int], None]] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections.abc import Callable
from pathlib import Path

from gatelogue_aggregator.sources.wiki_airport import WikiAirport
from gatelogue_aggregator.sources.air.wiki_airport import WikiAirport

_EXTRACTORS: list[Callable[[WikiAirport, Path, int], None]] = []

Expand Down
2 changes: 1 addition & 1 deletion gatelogue-aggregator/src/gatelogue_aggregator/types/air.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import msgspec
import rich.progress

from gatelogue_aggregator.sources.directional_flights import DIRECTIONAL_FLIGHT_AIRLINES
from gatelogue_aggregator.sources.air.hardcode import DIRECTIONAL_FLIGHT_AIRLINES
from gatelogue_aggregator.types.base import BaseContext, Node, Source, Sourced

if TYPE_CHECKING:
Expand Down
11 changes: 3 additions & 8 deletions gatelogue-aggregator/src/gatelogue_aggregator/types/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import networkx as nx
import rich

from gatelogue_aggregator.utils import search_all

if TYPE_CHECKING:
from collections.abc import Callable, Container, Iterator

Expand All @@ -20,7 +22,7 @@ class Ser(msgspec.Struct, kw_only=True):


class BaseContext(ToSerializable):
g: nx.MultiGraph[uuid.UUID]
g: nx.MultiGraph

def __init__(self):
self.g = nx.MultiGraph()
Expand Down Expand Up @@ -264,10 +266,3 @@ class Source(metaclass=SourceMeta):

def __init__(self):
rich.print(f"[yellow]Retrieving from {self.name}")


def search_all(regex: re.Pattern[str], text: str) -> Iterator[re.Match[str]]:
pos = 0
while (match := regex.search(text, pos)) is not None:
pos = match.end()
yield match
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from __future__ import annotations

import datetime
from pathlib import Path
from typing import TYPE_CHECKING, Self, override, cast
from typing import TYPE_CHECKING, Self, cast, override

import msgspec
import networkx as nx
import pygraphviz

if TYPE_CHECKING:
from collections.abc import Iterable
from pathlib import Path

import pygraphviz

import rich
import rich.progress

from gatelogue_aggregator.types.air import AirContext, AirSource, Flight, Airport, Airline, Gate
from gatelogue_aggregator.types.air import AirContext, Airline, Airport, AirSource, Flight, Gate
from gatelogue_aggregator.types.base import Node, ToSerializable


Expand Down
14 changes: 14 additions & 0 deletions gatelogue-aggregator/src/gatelogue_aggregator/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
import re
from collections.abc import Iterator


def search_all(regex: re.Pattern[str], text: str) -> Iterator[re.Match[str]]:
pos = 0
while (match := regex.search(text, pos)) is not None:
pos = match.end()
yield match

0 comments on commit 6e213f0

Please sign in to comment.