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 [156]:
import os
import arrow
import json
from TwitterFollowBot import TwitterBot
In [157]:
rdtwb = TwitterBot('/home/wcmckee/github/wcmckee-notebook/config.txt')
In [ ]:
In [158]:
prodir = ('/home/wcmckee/sellcoffee/products/')
In [159]:
lsprod = os.listdir(prodir)
In [160]:
print (lsprod)
In [162]:
sellwhat = input('Sell what: ')
In [163]:
fpathz = (prodir + sellwhat + '/' + sellwhat + '-amount')
In [164]:
#Open the file up and increase the sale number by one.
selinp = open(fpathz, 'r')
cursal = selinp.read()
selinp.close()
In [165]:
print (cursal)
In [166]:
conint = int(cursal)
In [167]:
#1 is amount to sell. Maybe raw_input enter int to sell more
#than one
amounsel = input('Amount to sell: ')
amount = int(amounsel)
newintz = conint + amount
In [170]:
fildir = (prodir + sellwhat + '/' + sellwhat + '-amount')
In [171]:
sewha = open(fildir, 'w')
sewha.write(str(newintz))
sewha.close()
In [172]:
opfolaz = open(fildir, 'r')
print (opfolaz.read())
In [173]:
opfolaz.close()
In [174]:
#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 [175]:
locdict = dict()
In [176]:
autc = arrow.utcnow()
In [177]:
hrsaledict = dict()
In [178]:
authr = autc.strftime('%H')
In [179]:
aumin = autc.strftime('%M')
In [180]:
ausec =autc.strftime('%S')
In [181]:
str(autc.date())
Out[181]:
In [182]:
auall = authr + aumin + ausec
In [183]:
fzaq = (str(autc.date()) + '-' + auall)
In [184]:
opcose = open(prodir + sellwhat + '/' + sellwhat + '-price', 'r')
In [185]:
oprdz = opcose.read()
opcose.close()
In [186]:
#price per item
print (oprdz)
In [187]:
totopr = int(oprdz) * newintz
In [188]:
totopr
Out[188]:
In [189]:
hrsaledict.update({auall : amount})
In [190]:
locdict.update({'product' : sellwhat, 'amount' : amount, 'time': auall, 'date': str(autc.date()), 'cost': totopr})
In [191]:
lcojson = json.dumps(locdict)
In [192]:
lcojson
Out[192]:
In [ ]:
In [193]:
os.urandom(7)
Out[193]:
In [197]:
os.mkdir('/home/wcmckee/sellcoffee/archive/')
In [198]:
salcoj = open('/home/wcmckee/sellcoffee/archive/' + fzaq + '.json', 'w')
salcoj.write(lcojson)
salcoj.close()
In [199]:
#7 character unique id for each transaction
#More than 1 product type sale transaction.
In [200]:
#Add another product? Y/n Question after the amount of product.
#
In [ ]:
In [202]:
rdtwb.send_tweet('Sold ' + sellwhat + ' amount is ' + amounsel + '. Price is' + str(totopr))
Out[202]:
In [ ]: