Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
iiPythonx committed Oct 7, 2024
1 parent 044c9a4 commit a931ccd
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 8 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.2"
__version__ = "0.7.3"
4 changes: 2 additions & 2 deletions usps/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def ordinal(day: int) -> str:

# Print out steps
location_max = len(max(package.steps, key = lambda _package: len(_package.location)).location)
for step in package.steps:
for step in package.steps[:10]:
location_block = f"[yellow]{step.location}[/]{' ' * (location_max - len(step.location))}"
con.print(f"\t[cyan]{step.details}[/]\t{location_block}\t[bright_blue]{get_delta(step.location, step.time)}[/]")

Expand All @@ -75,7 +75,7 @@ def command_track(tracking_number: typing.Annotated[typing.Optional[str], typer.
@app.command("add")
def command_add(tracking_numbers: list[str]) -> None:
"""Add tracking numbers to your package list."""
packages.save(packages.load() | {number: "" for number in tracking_numbers})
packages.save(packages.load() | {number: None for number in tracking_numbers})
for tracking_number in tracking_numbers:
con.print(f"[green]✓ USPS {tracking_number} added to your package list.[/]")

Expand Down
5 changes: 2 additions & 3 deletions usps/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Modules
import json
import typing
from pathlib import Path

# Initialization
Expand All @@ -14,13 +13,13 @@ class PackageStorage:
def __init__(self) -> None:
self.package_file = usps_global / "packages.json"

def load(self) -> typing.Mapping[str, str | None]:
def load(self) -> dict[str, str | None]:
if not self.package_file.is_file():
return {}

return json.loads(self.package_file.read_text())

def save(self, _packages: typing.Mapping[str, str | None]) -> None:
def save(self, _packages: dict[str, str | None]) -> None:
self.package_file.write_text(json.dumps(_packages, indent = 4))

packages = PackageStorage()
Expand Down
4 changes: 2 additions & 2 deletions usps/tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def __init__(self) -> None:

@staticmethod
def __map_step_details(details: str) -> str:
if "between" in details.lower():
if "expected delivery" in details.lower():
return "Delivering"

details = details.split(", ")[-1].lower()
Expand Down Expand Up @@ -188,7 +188,7 @@ def find_object(class_name: str, parent: Tag | None = None) -> Tag | None:
# Estimated delivery
[
datetime.strptime(
f"{get_text(find_object('date')).zfill(2)} {month} {year} {time}",
f"{get_text(find_object('date')).zfill(2)} {month} {year} {time.strip()}",
"%d %B %Y %I:%M%p"
)
for time in times
Expand Down

0 comments on commit a931ccd

Please sign in to comment.