X-Git-Url: https://git.ucc.asn.au/?p=uccvend-vendserver.git;a=blobdiff_plain;f=VendServer%2FSnackConfig.py;fp=VendServer%2FSnackConfig.py;h=231407480171c5078e55d3aaedc1e361e9a24bb5;hp=0000000000000000000000000000000000000000;hb=6c130dc942392ccc8b7ffa0ec2ede5f9327f99e6;hpb=e423f11f190d685156cb557319b169d2b79b752f diff --git a/VendServer/SnackConfig.py b/VendServer/SnackConfig.py new file mode 100755 index 0000000..2314074 --- /dev/null +++ b/VendServer/SnackConfig.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python + +class VendingException( Exception ): pass + +import subprocess +import os, re + +def get_snack( slot ): + + if slot == "--": + return (0, 'nothing', 'Nothing') + cmd = 'dispense iteminfo snack:%s' % slot +# print 'cmd = %s' % cmd + try: +# info = subprocess.check_output(["dispense","iteminfo",'snack:%s'%slot]) + raw = os.popen(cmd) + info = raw.read() + raw.close() +# print 'cmd (2) = %s' % cmd +# print 'info = "%s"' % info + m = re.match("\s*[a-z]+:\d+\s+(\d+)\.(\d\d)\s+([^\n]+)", info) + val = ( int(m.group(1))*100 + int(m.group(2)), m.group(3), m.group(3) ) +# print 'Price: %i, Name: %s' % (val[0], val[1]) + except BaseException as e: + print "BaseException" + print e + val = (0, 'error', 'Error') + except: + print "Unknown exception" + val = (0, 'error', 'Error') + return val + +def get_price( slot ): + p, sn, n = get_snacks( slot ) + return p + +def get_name( slot ): + p, sn, n = get_snacks( slot ) + return n + +def get_short_name( slot ): + p, sn, n = get_snacks( slot ) + return sn + +if __name__ == '__main__': + print "Don't run this"