Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
CLI: Colored live output
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmouchet committed Jan 30, 2020
1 parent 3bb0b8a commit b82fd22
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions locomotive/cli/commands/live.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import dateparser
import requests
import tableformatter as tf
from colored import bg

from ...api.gc import BoardRequest, Client
from ...models import BoardEntry, Station
Expand All @@ -18,7 +19,7 @@ def get_rows(entries: List[BoardEntry]) -> List[tuple]:
(
x.tofrom.name,
f"{x.transport.label} {x.transport.number}",
x.time,
x.time.strftime("%H:%M"),
f"{x.delay} min",
x.platform,
)
Expand All @@ -34,6 +35,7 @@ def get_rows(entries: List[BoardEntry]) -> List[tuple]:
# default="pretty",
# help="Output format.",
# )
@click.option("--color/--no-color", default=False)
@click.pass_context
def live(ctx: click.Context, **args: str) -> None:
"""
Expand All @@ -48,10 +50,16 @@ def live(ctx: click.Context, **args: str) -> None:

client = Client(stations)

dep_gs = None
arr_gs = None
if args["color"]:
dep_gs = tf.AlternatingRowGrid(bg(25), bg(18))
arr_gs = tf.AlternatingRowGrid(bg(34), bg(28))

departures = client.board_request(BoardRequest(station, "departure"))
cols = ["Destination", "Number", "Time", "Delay", "Platform"]
click.echo(tf.generate_table(get_rows(departures), cols))
click.echo(tf.generate_table(get_rows(departures), cols, grid_style=dep_gs))

arrivals = client.board_request(BoardRequest(station, "arrival"))
cols = ["Origin", "Number", "Time", "Delay", "Platform"]
click.echo(tf.generate_table(get_rows(arrivals), cols))
click.echo(tf.generate_table(get_rows(arrivals), cols, grid_style=arr_gs))
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ requests = "^2.20"
tableformatter = "^0.1.4"
text-unidecode = "^1.3"
py-money = "^0.4.0"
colored = "^1.4.2"

[tool.poetry.dev-dependencies]
# https://github.com/python-poetry/poetry/issues/649
Expand Down

0 comments on commit b82fd22

Please sign in to comment.