Done added coke pricechecking
[zanchey/dispense2.git] / sql-edition / servers / VendServer.py
index e18d8a3..0126063 100755 (executable)
@@ -10,7 +10,7 @@ import logging, logging.handlers
 from traceback import format_tb
 if USE_DB: import pg
 from time import time, sleep, mktime, localtime
-from popen2 import popen2
+from subprocess import Popen, PIPE
 from LATClient import LATClient, LATClientException
 from SerialClient import SerialClient, SerialClientException
 from VendingMachine import VendingMachine, VendingException
@@ -94,13 +94,10 @@ class DispenseDatabase:
 
 def scroll_options(username, mk, welcome = False):
        if welcome:
-               # Balance checking: crap code, [DAA]'s fault
-               # Updated 2011 to handle new dispense [MRD]
-               raw_acct = os.popen('dispense acct %s' % username)
-               acct = raw_acct.read()
+               # Balance checking
+               acct, unused = Popen(['dispense', 'acct', username], close_fds=True, stdout=PIPE).communicate()
                # this is fucking appalling
                balance = acct[acct.find("$")+1:acct.find("(")].strip()
-               raw_acct.close()
         
                msg = [(center('WELCOME'), False, TEXT_SPEED),
                           (center(username), False, TEXT_SPEED),
@@ -112,10 +109,8 @@ def scroll_options(username, mk, welcome = False):
        # Get coke contents
        cokes = []
        for i in range(0, 7):
-               cmd = 'dispense iteminfo coke:%i' % i
-               raw = os.popen(cmd)
-               info = raw.read()
-               raw.close()
+               args = ('dispense', 'iteminfo', 'coke:%i' % i)
+               info, unused = Popen(args, close_fds=True, stdout=PIPE).communicate()
                m = re.match("\s*[a-z]+:\d+\s+(\d+)\.(\d\d)\s+([^\n]+)", info)
                cents = int(m.group(1))*100 + int(m.group(2))
                cokes.append('%i %i %s' % (i, cents, m.group(3)));
@@ -468,7 +463,9 @@ def make_selection(v, vstatus):
 
 def price_check(v, vstatus):
        if vstatus.cur_selection[1] == '8':
-               v.display(center('SEE COKE'))
+               args = ('dispense', 'iteminfo', 'coke:' + vstatus.cur_selection[0])
+               info, unused = Popen(args, close_fds=True, stdout=PIPE).communicate()
+               dollarprice = re.match("\s*[a-z]+:\d+\s+(\d+\.\d\d)\s+([^\n]+)", info).group(1)
        else:
                # first see if it's a named slot
                try:
@@ -476,7 +473,7 @@ def price_check(v, vstatus):
                except:
                        price, shortname, name = get_snack( '--' )
                dollarprice = "$%.2f" % ( price / 100.0 )
-               v.display(vstatus.cur_selection+' - %s'%dollarprice)
+       v.display(vstatus.cur_selection+' - %s'%dollarprice)
 
 
 def handle_getting_pin_key(state, event, params, v, vstatus):

UCC git Repository :: git.ucc.asn.au