Product Sell

Script to sell a product.

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


['debian', 'internet', 'python', 'hat', 'pepsi', 'fedora', 'coke', 'chips']

In [190]:
sellwhat = raw_input('Sell what: ')


Sell what: internet

In [191]:
fpathz = (prodir + sellwhat + '/' + sellwhat + '-amount')

In [192]:
fpathz


Out[192]:
'/home/wcmckee/sellcoffee/products/internet/internet-amount'

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


0

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


Amount to sell: 3

In [198]:
newintz


Out[198]:
3

In [199]:
fildir = (prodir + sellwhat + '/' + sellwhat + '-amount')

In [200]:
fildir


Out[200]:
'/home/wcmckee/sellcoffee/products/internet/internet-amount'

In [200]:


In [201]:
sewha = open(fildir, 'w')

sewha.write(str(newintz))

sewha.close()

In [202]:
opfolaz = open(fildir, 'r')

print opfolaz.read()


3

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]:
'2015-03-02'

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


150

In [217]:
totopr = int(oprdz) * newintz

In [218]:
totopr


Out[218]:
450

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]:
'{"date": "2015-03-02", "product": "internet", "cost": 450, "amount": 3, "time": "184336"}'

In [222]:
os.urandom(7)


Out[222]:
'\x8a1\xe6\xc6\xd3\xd5k'

In [223]:
fzaq


Out[223]:
'2015-03-02-184336'

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 [ ]: