Skip to content

Commit

Permalink
add autorefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Oct 7, 2024
1 parent 1496333 commit 1d831bb
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion usps/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.7.3"
__version__ = "0.7.4"
19 changes: 16 additions & 3 deletions usps/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2024 iiPython

# Modules
import time
import typing
import textwrap

Expand Down Expand Up @@ -56,7 +57,10 @@ def ordinal(day: int) -> str:
print()

@app.command("track")
def command_track(tracking_number: typing.Annotated[typing.Optional[str], typer.Argument()] = None) -> None:
def command_track(
tracking_number: typing.Annotated[typing.Optional[str], typer.Argument()] = None,
refresh: typing.Annotated[typing.Optional[int], typer.Option(help = "Auto refresh the tracking information every x minutes.")] = None,
) -> None:
"""Track the specified tracking numbers, tracking your package list if no tracking
number is specified."""

Expand All @@ -69,8 +73,17 @@ def command_track(tracking_number: typing.Annotated[typing.Optional[str], typer.
if not tracking_numbers:
return con.print("[red]× You don't have any default packages to track.[/]")

for package, name in tracking_numbers.items():
show_package(package, name, tracking.track_package(package))
if refresh is not None:
while True:
print("\033[H\033[2J", end = "")
for package, name in tracking_numbers.items():
show_package(package, name, tracking.track_package(package))

time.sleep(refresh * 60)

else:
for package, name in tracking_numbers.items():
show_package(package, name, tracking.track_package(package))

@app.command("add")
def command_add(tracking_numbers: list[str]) -> None:
Expand Down
3 changes: 2 additions & 1 deletion usps/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Package:
"arriving on time": "Package On Time",
"accepted at usps origin facility": "Accepted",
"arrived at usps facility": "At Facility",
"departed usps facility": "Left Facility"
"departed usps facility": "Left Facility",
"package acceptance pending": "Accepted"
}

# BS4 wrappers
Expand Down

0 comments on commit 1d831bb

Please sign in to comment.