Metadata-Version: 2.4
Name: parcelgr
Version: 0.1.0
Summary: Track a parcel with Greek couriers (Speedex, Taxydema, ACS) from the tracking number alone, with no browser, API key or account
Author: Konstantinos Georgiou
License-Expression: MIT
Project-URL: Homepage, https://github.com/drkostas/parcelgr
Project-URL: Changelog, https://github.com/drkostas/parcelgr/blob/main/CHANGELOG.md
Keywords: tracking,parcel,courier,shipping,greece,speedex,acs,taxydema
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Utilities
Classifier: Intended Audience :: Developers
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# parcelgr

Ask a Greek courier where a parcel is, without knowing which courier it is.

Tracking numbers arrive in confirmation emails without a courier's name attached, and each
courier has its own page, its own wording and its own idea of what counts as an event. This
reads the number's shape, picks the right carrier, and gives back the parcel's history in the
carrier's own words.

No browser, no API key, no account. One HTTP request per carrier, two for ACS.

```python
import parcelgr

parcel = parcelgr.track("1234567890")
print(parcel.carrier)          # acs
print(parcel.last.status)      # Στο αρμόδιο κατάστημα παράδοσης
print(parcel.destination)      # the branch holding it, when the carrier names one
```

A mixed list needs no sorting first.

```python
for parcel in parcelgr.track_all(["JJD014600099900011122", "IHB9900011122", "1234567890"]):
    if isinstance(parcel, parcelgr.TrackingError):
        print("could not read:", parcel)
    else:
        print(parcel.carrier, parcel.last.at, parcel.last.status)
```

From a shell.

```
$ parcelgr 1234567890 JJD014600099900011122
```

## For agents

The package ships a skill at `src/parcelgr/skills/parcelgr/SKILL.md`, so an assistant handed a
tracking number can find the courier, read the history and know what the statuses mean without
opening a browser. That is what it was built for: the couriers' own pages are single-page
applications behind consent banners, and driving a browser to read one costs far more than a
single HTTP request. The skill also records what the statuses mean in practice, which is the
part that decides whether someone should stay at home or go to a branch.

## Install

```
pip install parcelgr
```

Python 3.9 or newer. No dependencies.

Until the first release reaches PyPI, install it from a checkout:

```
pip install git+https://github.com/drkostas/parcelgr
```

## Carriers

| Carrier | Numbers look like | How it is read |
|---|---|---|
| Speedex | `JJD0146` and 15 to 22 digits | Its track-and-trace page renders the history server side, so the page is parsed. |
| Taxydema | `IHB` and 8 to 16 digits | Its tracking page is a small Vue application calling an undocumented JSON endpoint, which is called directly. |
| ACS | exactly 10 digits | It has a JSON API that refuses an anonymous request with HTTP 406. The header it wants is published on its own tracking page, so the page is read first for that value. |

Adding a carrier is one module with four names, `NAME`, `matches`, `parse` and `track`, added
to the list in `carriers/__init__.py`. Keeping `parse` separate from `track` is what lets the
tests run on saved responses with no network.

### Known gap, DHL Express

DHL Express is not supported. Its unauthenticated tracking endpoint does not answer a plain
HTTP client, and its documented API returns 401 without a key, so there is nothing to read
without credentials. A DHL parcel handed to a Greek courier for the last leg gets a new number
from that courier, and that number works here.

**A DHL Express waybill is ten digits, and so is an ACS tracking number**, so `detect()` cannot
tell them apart and will answer `acs` for both. Nothing can do better from the number alone. Pass
a DHL number to `track()` and ACS is asked about it and says it has no such parcel, which surfaces
as `ParcelNotFound` rather than as a wrong answer. If you hold both numbers for one shipment, as
the forwarding email usually gives you, track the Greek one.

## What you get back

`track()` returns a frozen `Parcel`.

| Field | Meaning |
|---|---|
| `number`, `carrier` | what was asked, and who answered |
| `events` | the history, oldest first, each one an `Event` with `at`, `status` and `place` |
| `last` | the newest event, or `None` |
| `delivered` | `True`, `False`, or `None` when the carrier does not say outright |
| `note` | a free-text remark the carrier attached |
| `destination`, `destination_phone` | the branch holding the parcel, when the carrier names one |

Wording is never translated or mapped onto a shared vocabulary. Carriers disagree about what
their own states mean, and a parcel's fate often turns on the exact phrase, so you see what the
carrier actually said.

## Watchlists

There is no watchlist in the package. Numbers are your data, and where you keep them is your
business, so `track_all()` takes any iterable of strings. A few lines of your own code reading
a JSON file is all a watchlist needs to be.

## Errors

Everything raised inherits from `TrackingError`.

| Error | When |
|---|---|
| `UnknownCarrier` | no carrier recognises the number's shape, or a name passed to `carrier=` is not one of ours |
| `ParcelNotFound` | a carrier answered and says it has no such parcel |
| `TrackingError` | a network failure, or an answer in a shape the reader does not know |

`track_all()` never raises. It yields a `Parcel` or the error for each number, in order, so one
unreachable carrier does not hide the others.

## Notes from building the readers

Two things cost real time and are worth knowing before changing a reader.

**Speedex puts the description before the timestamp.** Inside each timeline card the wording
comes first and the date second. A parser that splits the page on dates pairs every description
with the previous event, which shifts the whole history by one. A parcel scanned back into its
branch then reads as a failed delivery, and so does everything else. There is a test named
after this.

**ACS answers 406, not 404, when the header is missing.** `X-Encrypted-Key` looks like a secret
and is not. The tracking page carries it as a `publictoken` attribute and its own front end
copies it into session storage. The value rotates, so the reader takes it fresh on every call
rather than storing it.

## Tests

```
pip install -e ".[test]"
pytest
```

Every test runs on a saved response and none reaches the network, which one of the tests
enforces. Every tracking number, address, telephone number and place name in the fixtures is
invented.

## Licence

MIT.
