Making trackbert a proper package

Adding .gitlab-ci.yml
This commit is contained in:
Kumi 2023-08-25 07:37:43 +02:00
parent 1d90de9205
commit 619aa99e35
Signed by: kumi
GPG key ID: ECBCC9082395383F
15 changed files with 81 additions and 21 deletions

28
.gitlab-ci.yml Normal file
View file

@ -0,0 +1,28 @@
image: python:3.10
stages:
# - test
- publish
before_script:
- python -V
- python -m venv venv
- source venv/bin/activate
- pip install -U pip
- pip install .
# - echo "[KeyDelivery]" > config.ini
# - echo "key = ${KEYDELIVERY_KEY}" >> config.ini
# - echo "secret = ${KEYDELIVERY_SECRET}" >> config.ini
#test:
# stage: test
# script: python -m unittest test.py
publish:
stage: publish
script:
- pip install -U hatchling twine build
- python -m build .
- python -m twine upload --username __token__ --password ${PYPI_TOKEN} dist/*
only:
- tags

View file

@ -1,11 +1,16 @@
# Trackbert
A simple Python script for tracking shipments through [KeyDelivery](https://kd100.com).
A simple Python script for tracking shipments, primarily through [KeyDelivery](https://kd100.com).
If your system provides `notify-send`, you will get a desktop notification when the status of your shipment changes.
Status information is stored in a SQLite database.
## Currently supported tracking providers
- [KeyDelivery](https://kd100.com) (paid, provides tracking for most carriers)
- [Austrian Post](https://www.post.at)
## Requirements
The script was developed and tested on Arch Linux using Python 3.11. The "Never" type hint is used, so I suppose it will not work on older Python versions. It should work on any Linux distribution. You can technically run it on Windows and macOS as well, but you will not get desktop notifications.
@ -19,7 +24,7 @@ git clone https://kumig.it/kumitterer/trackbert.git
cd trackbert
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
pip install .
```
Then copy `config.dist.ini` to `config.ini` and fill in your KeyDelivery API details, which you can find in your [KeyDelivery API management](https://app.kd100.com/api-management). You can find your API key in your KeyDelivery account settings.

32
pyproject.toml Normal file
View file

@ -0,0 +1,32 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "trackbert"
version = "0.1.0"
authors = [
{ name="Kumi Mitterer", email="trackbert@kumi.email" },
]
description = "Python application tracking your shipments"
readme = "README.md"
license = { file="LICENSE" }
requires-python = ">=3.10"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
dependencies = [
"pykeydelivery",
"postat",
"sqlalchemy",
"python-dateutil",
]
[project.urls]
"Homepage" = "https://kumig.it/kumitterer/trackbert"
"Bug Tracker" = "https://kumig.it/kumitterer/trackbert/issues"
[project.scripts]
trackbert = "trackbert.__main__:main"

View file

@ -1,4 +0,0 @@
pykeydelivery
postat
sqlalchemy
python-dateutil

View file

@ -8,11 +8,10 @@ import logging
import asyncio
from typing import Tuple, Never, Optional
from classes.database import Database
from classes.tracker import Tracker
from .classes.database import Database
from .classes.tracker import Tracker
if __name__ == "__main__":
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--tracking-number", "-n", type=str, required=False)
parser.add_argument("--carrier", "-c", type=str, required=False)
@ -76,3 +75,6 @@ if __name__ == "__main__":
tracker = Tracker()
asyncio.run(tracker.start_async())
if __name__ == "__main__":
main()

View file

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 4.5 KiB

View file

@ -7,7 +7,7 @@ from pathlib import Path
from typing import Optional, Tuple, Never
from .database import Database
from trackers.base import BaseTracker
from ..trackers.base import BaseTracker
from pykeydelivery import KeyDelivery
@ -36,14 +36,14 @@ class Tracker:
logging.debug(f"Found API {api.stem}")
module = importlib.import_module(f"trackers.{api.stem}")
module = importlib.import_module(f"trackbert.trackers.{api.stem}")
if "tracker" in module.__dict__:
tracker = module.tracker
logging.debug(f"Found tracker {api.stem}")
try:
carriers = tracker.supported_carriers()
api = tracker()
carriers = api.supported_carriers()
for carrier, priority in carriers:
self.apis.append((carrier, priority, api))

View file

View file

@ -5,8 +5,7 @@ class BaseTracker:
def get_status(self, tracking_number, carrier):
raise NotImplementedError()
@staticmethod
def supported_carriers():
def supported_carriers(self):
"""Defines the carriers supported by this tracker.
Returns:

View file

@ -1,5 +1,5 @@
from .base import BaseTracker
from classes.database import Event
from ..classes.database import Event
from pykeydelivery import KeyDelivery as KeyDeliveryAPI
@ -34,8 +34,7 @@ class KeyDelivery(BaseTracker):
raw_event=json.dumps(event),
)
@staticmethod
def supported_carriers():
def supported_carriers(self):
return [
("*", 1),
]

View file

@ -1,5 +1,5 @@
from .base import BaseTracker
from classes.database import Event
from ..classes.database import Event
import json
@ -28,8 +28,7 @@ class PostAT(BaseTracker):
raw_event=json.dumps(event),
)
@staticmethod
def supported_carriers():
def supported_carriers(self):
return [
("austrian_post", 100),
]