Package: dmsclient
Python3 library with command line interface to interact with the Drink Management System (DMS) of thestudent council TF Uni Freiburg.Example use case: Order product from the command line.$dmsorderspezi-ujohann(1)JohannesMustermann(2)JohannaMusterfrau(3)JohannMustermenschPleaseenteranumberbetween1and3:1Order1NetteMarkeSpezi(0.70€)forJohannesMustermann?[YES/no]yOrdersuccessful.Getting StartedPrerequisitesYou needpython 3.5or newer andpip.
For development you also need git installed on your machine.InstallationInstall the dmsclient library and command line interface simply fromPyPi:pip3installdmsclientFor developers it’s recommended to install from source viedevelop.
Then all changes in code are automatically available in the library and command line without reinstallation.gitclonegit@<giturl>:<user>/dmsclient.gitcddmsclientpython3setup.pydevelopCommand LineThe installation ofdmsclientprovides a command line interfacedms.
For authentication you have to generate a token key in your dms profile settings.
Add your token to a.dmsrcfile in your home folder.[DEFAULT]
Token = XxxxxXXXxxxxxXXXXxxxxxxxXXXThen you can start usingdms. You’ll find all available commands viadms--helpUser and product names don’t have to be added exactly, but are estimated from what you type. E.g.:$dmsbuyapfel-umustBuyApfelschorle(0.70€)forMaxMustermann?[Y/n]LibraryFor communication with the DMS via REST you can use theDmsClientclass 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 withDmsConfig.importosfromrandomimportsamplefromdmsclientimportDmsClient,DmsConfigrcfile=os.path.expanduser('~/.dmsrc')cfg=DmsConfig()cfg.read(rcfile)API functions ofDmsClientusually return coroutines for asynchronous access.importasyncioasyncdefasync_order_random_stuff_for_last_customer(loop,cfg):asyncwithDmsClient(cfg.token,cfg.api)asdms:# register tasks which can run in parallelproducts_task=loop.create_task(dms.products)sales_task=loop.create_task(dms.sale_history(num_days=1))# execute tasks to fetch data in parallelavailable_products=[pforpinawaitproducts_taskifp.quantity>0]random_product=sample(available_products,1)[0]last_sale=(awaitsales_task)[0]# order random productawaitdms.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 fashionfromsyncerimportsync@syncasyncdeforder_random_stuff_for_last_customer(cfg):asyncwithDmsClient(cfg.token,cfg.api)asdms:# synchronous fetch dataproducts=awaitdms.productssales=awaitdms.sale_history(num_days=1)available_products=[pforpinproductsifp.quantity>0]random_product=sample(available_products,1)[0]last_sale=sales[0]# order random productawaitdms.add_order(random_product.id,last_sale['profile'])order_random_stuff_for_last_customer(cfg)Alternative:loop=asyncio.get_event_loop()# Connect synchronouslyclient=dms.DmsClient(cfg.token,cfg.api)client.connect()# Read productsproducts=loop.run_until_complete(client.products)AuthorsInitiated byDavid-Elias Künstle<kuenstld[at]tf.uni-freiburg> /Githubbut seecontributorsfor a full list of contributions.Licensedmsclient is available under theMIT LicenseAcknowledgementsBig thanks to the DMS and DMS-API developers!