Giter Site home page Giter Site logo

ok-17track's Introduction

django-ok-17track PyPI version

Build status Code health Project Status Python versions PyPI downloads Software license Project Status

django-17track is an unofficial 17track.com API wrapper for Django.

Installation

Install with pip:

$ pip install django-ok-17track

Update INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'track17',
    ...
]

Make migrations

$ python manage.py migrate

Available settings

TRACK17_API_KEY - API key for service.

TRACK17_API_KEY_FUNCTION - Custom function to return API key, if you want to store it outside the Django settings.

TRACK17_COUNTRIES_URL - Url to grab countries. Uses https://www.17track.net/en/apicountry.

TRACK17_CARRIERS_URL - Url to grab carriers. Uses https://www.17track.net/en/apicarrier.

Basic example to use:

How to get all countries and carriers:

python managet.py populate_carriers

How to register tracking number and get it's info:

from typing import List, TYPE_CHECKING

from rest_framework import serializers
from track17.services import register_track, get_track_info, get_track_info_as_packages
from track17.exceptions import DateProcessingError

if TYPE_CHECKING:
    from track17.entity import PackageEntity


# try to register tracking number at 17track API
try:
    register_track('tracking_number')
except DateProcessingError as exc:
    raise serializers.ValidationError(str(exc))

# try to fetch an actual info about a tracking number
try:
    response: Dict = get_track_info('tracking_number')
except DateProcessingError as exc:
    raise serializers.ValidationError(str(exc))

accepted_packages = response.get('accepted', [])

# return packages info as a list of `PackageEntity` (dataclass instance) objects
# in a readable way with a represantion of carriers and countries as Django model instances
packages: List['PackageEntity'] = get_track_info_as_packages(accepted)

Or can use 17track adapter directly:

from track17.track17 import Track17Adapter


track17 = Track17Adapter()
response = track17.register('number1', 'number2')
response = track17.get_track_info('number1', 'number2')

ok-17track's People

Contributors

lowerdeez avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.