Skip to main content

Python3 library with command line interface to interact with the Drink Management System (DMS) of the student council TF Uni Freiburg.

Example use case: Order product from the command line.

$ dms order spezi -u johann
(1) Johannes Mustermann
(2) Johanna  Musterfrau
(3) Johann   Mustermensch
Please enter a number between 1 and 3: 1
Order 1 NetteMarke Spezi (0.70€) for Johannes Mustermann? [YES/no] y
Order successful.

Getting Started

Prerequisites

You need python 3.5 or newer and pip. For development you also need git installed on your machine.

Installation

Install the dmsclient library and command line interface simply from PyPi:

pip3 install dmsclient

For developers it’s recommended to install from source vie develop. Then all changes in code are automatically available in the library and command line without reinstallation.

git clone git@<git url>:<user>/dmsclient.git
cd dmsclient

python3 setup.py develop

Command Line

The installation of dmsclient provides a command line interface dms. For authentication you have to generate a token key in your dms profile settings. Add your token to a .dmsrc file in your home folder.

[DEFAULT]
Token = XxxxxXXXxxxxxXXXXxxxxxxxXXX

Then you can start using dms. You’ll find all available commands via

dms --help

User and product names don’t have to be added exactly, but are estimated from what you type. E.g.:

$ dms buy apfel -u must
Buy Apfelschorle (0.70€) for Max Mustermann? [Y/n]

Library

For communication with the DMS via REST you can use the DmsClient class provided by this library. Authentication is provided via a token key which you can generate in the DMS profile settings. Usually the token is stored in an RC file readable with DmsConfig.

import os
from random import sample

from dmsclient import DmsClient, DmsConfig


rcfile = os.path.expanduser('~/.dmsrc')
cfg = DmsConfig()
cfg.read(rcfile)

API functions of DmsClient usually return coroutines for asynchronous access.

import asyncio


async def async_order_random_stuff_for_last_customer(loop, cfg):
    async with DmsClient(cfg.token, cfg.api) as dms:
       # register tasks which can run in parallel
       products_task = loop.create_task(dms.products)
       sales_task = loop.create_task(dms.sale_history(num_days=1))

       # execute tasks to fetch data in parallel
       available_products = [p for p in await products_task
                             if p.quantity > 0]
       random_product = sample(available_products, 1)[0]
       last_sale = (await sales_task)[0]

       # order random product
       await dms.add_order(random_product.id, last_sale['profile'])

loop = asyncio.get_event_loop()
loop.run_until_complete(async_order_random_stuff_for_last_customer(loop, cfg))

Still, you can use the library also in a synchronous fashion

from syncer import sync


@sync
async def order_random_stuff_for_last_customer(cfg):
    async with DmsClient(cfg.token, cfg.api) as dms:
        # synchronous fetch data
        products = await dms.products
        sales = await dms.sale_history(num_days=1)

        available_products = [p for p in products
                              if p.quantity > 0]
        random_product = sample(available_products, 1)[0]
        last_sale = sales[0]

        # order random product
        await dms.add_order(random_product.id, last_sale['profile'])


order_random_stuff_for_last_customer(cfg)

Alternative:

loop = asyncio.get_event_loop()

# Connect synchronously
client = dms.DmsClient(cfg.token, cfg.api)
client.connect()

# Read products
products = loop.run_until_complete(client.products)

Authors

Initiated by David-Elias Künstle <kuenstld[at]tf.uni-freiburg> / Github but see contributors for a full list of contributions.

License

dmsclient is available under the MIT License

Acknowledgements

Big thanks to the DMS and DMS-API developers!

Metadata

Release files for dmsclient 1.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dmsclient 1.5.2
File Size Uploaded
dmsclient-1.5.2.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dmsclient 1.5.2
File Interpreter ABI Platform
dmsclient-1.5.2-py3-none-any.whl Python 3 none any Details

Total release size: 22.2 kB

Release files / dmsclient-1.5.2.tar.gz

Download URL dmsclient-1.5.2.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
c6589f792b797c345abb2695fc746ca3a6dcfb8405275fecd5501c0bc4f656e5
BLAKE2b-256 checksum
How to use checksums
3b22a65a62699a08498177f9ac223b1a4922bbd3dedede6527ea8a5bdf7e2d79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release files / dmsclient-1.5.2-py3-none-any.whl

Download URL dmsclient-1.5.2-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7a24105e683aea52f400c8517ba53dc8806e305a673def06074b4fb4682a2719
BLAKE2b-256 checksum
How to use checksums
f58e7e5c695699ca18a74ee99a4f4ae889331aea61829d5eec28c94e888852e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1

Release history Release notifications | RSS feed

This release

1.5.2 This release

2 release files

1.5.1

2 release files

1.5.0

1 release file

1.4.1

1 release file

1.4.0

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.0

1 release file

1.1.1

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page