Gets products list from /sellcoffee/products folder. input what to sell. or input 4 digit code of product.
Input amount of product to sell
Processes the sale, increasing number of product filename by input amount to sell.
Creates dict of sale, includes time, date, product (inputed data), amount (inputed sales amount), served by, hostname of machine that processed transaction, e receipts.
In [185]:
import os
import arrow
import json
In [186]:
prodir = ('/home/wcmckee/sellcoffee/products/')
In [187]:
lsprod = os.listdir(prodir)
In [188]:
print lsprod
In [190]:
sellwhat = raw_input('Sell what: ')
In [191]:
fpathz = (prodir + sellwhat + '/' + sellwhat + '-amount')
In [192]:
fpathz
Out[192]:
In [193]:
#Open the file up and increase the sale number by one.
selinp = open(fpathz, 'r')
cursal = selinp.read()
selinp.close()
In [194]:
print cursal
In [195]:
conint = int(cursal)
In [197]:
#1 is amount to sell. Maybe raw_input enter int to sell more
#than one
amounsel = raw_input('Amount to sell: ')
amount = int(amounsel)
newintz = conint + amount
In [198]:
newintz
Out[198]:
In [199]:
fildir = (prodir + sellwhat + '/' + sellwhat + '-amount')
In [200]:
fildir
Out[200]:
In [200]:
In [201]:
sewha = open(fildir, 'w')
sewha.write(str(newintz))
sewha.close()
In [202]:
opfolaz = open(fildir, 'r')
print opfolaz.read()
In [203]:
opfolaz.close()
In [204]:
#Need to report back by updating dict() of 24 hour value
#that sale is +.
#Dict that is recect of current sale. Name of product, amount.
#Cost * amount.
#Paid by cash, eftpos, credit card etc...
#Change to be given.
In [205]:
locdict = dict()
In [206]:
autc = arrow.utcnow()
In [207]:
hrsaledict = dict()
In [208]:
authr = autc.strftime('%H')
In [209]:
aumin = autc.strftime('%M')
In [210]:
ausec =autc.strftime('%S')
In [211]:
str(autc.date())
Out[211]:
In [212]:
auall = authr + aumin + ausec
In [213]:
fzaq = (str(autc.date()) + '-' + auall)
In [214]:
opcose = open(prodir + sellwhat + '/' + sellwhat + '-price', 'r')
In [215]:
oprdz = opcose.read()
opcose.close()
In [216]:
#price per item
print oprdz
In [217]:
totopr = int(oprdz) * newintz
In [218]:
totopr
Out[218]:
In [157]:
hrsaledict.update({auall : amount})
In [219]:
locdict.update({'product' : sellwhat, 'amount' : amount, 'time': auall, 'date': str(autc.date()), 'cost': totopr})
In [220]:
lcojson = json.dumps(locdict)
In [221]:
lcojson
Out[221]:
In [222]:
os.urandom(7)
Out[222]:
In [223]:
fzaq
Out[223]:
In [224]:
salcoj = open('/home/wcmckee/sellcoffee/archive/' + fzaq + '.json', 'w')
salcoj.write(lcojson)
salcoj.close()
In [102]:
#7 character unique id for each transaction
#More than 1 product type sale transaction.
In [75]:
#Add another product? Y/n Question after the amount of product.
#
In [ ]: