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
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),
# 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)));
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:
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):