Product Add

Script to add a new product to list of them. Location is /home/wcmckee/sellcoffee/products.

Better to have a file for products or a folder? Might be easier to have a folder. Each product has rsa key - public and private key.

Make json restful api that has product list. Append new product to it whenever it's updated.


In [28]:
import os
import time
import datetime
import json
#from passlib.hash import pbkdf2_sha256
#import crypt, getpass, spwd
#from Crypto.PublicKey import RSA

In [ ]:


In [29]:
yearz = time.strftime("%y", time.gmtime())
monthz = time.strftime("%m", time.gmtime())
dayz = time.strftime("%d", time.gmtime())

In [30]:
datez = yearz + monthz + dayz

In [31]:
prodirz = ('/home/wcmckee/sellcoffee/products/')

In [32]:
prolis = os.listdir(prodirz)

In [33]:
print(prolis)


['thom', 'thomthomindex.json']

In [38]:
prodoadd = input('Name of product to add: ')


Name of product to add: crayons

In [39]:
prodirc = (prodirz + prodoadd)

In [40]:
os.mkdir(prodirc)

In [41]:
opmeta = open(prodirc + '/' +  prodoadd + '-amount', 'w')

opmeta.write('0')

opmeta.close()

In [42]:
opforc = open(prodirc + prodoadd + 'index.json', 'w')

In [43]:
dicprod = dict()

In [44]:
dicprod


Out[44]:
{}

In [ ]:


In [ ]:


In [ ]:


In [45]:
#id for each item. Starts at 1000 and up to 9999
#to make id it gets len of items in products folder and plus
#1000.

totprods = len(prolis)

newids = totprods + 1000

opmeta = open(prodirc + '/' +  prodoadd + '-id', 'w')

opmeta.write(str(newids))

opmeta.close()

In [46]:
#switching to folders for each product. Inside folder has rsa
#and rsa.public.

In [47]:
dicprod.update({'name' : prodoadd})

dicprod.update({'id' : str(newids)})

dicprod.update({'datecreate' : datez})

In [60]:
tigm = time.strftime("%H %M %S", time.gmtime())

In [63]:
timech =tigm.replace(' ', '')

In [65]:
dicprod.update({'timecreate' : timech})

In [ ]:


In [66]:
dicprod


Out[66]:
{'datecreate': '150731',
 'id': '1002',
 'name': 'crayons',
 'timecreate': '140739'}

In [49]:
prodoaddz = dict()

In [51]:
prodoaddz.update({prodoadd : dicprod})

In [52]:
prodoaddz


Out[52]:
{'crayons': {'datecreate': '150731', 'id': '1002', 'name': 'crayons'}}

In [55]:
json.dumps(prodoaddz)


Out[55]:
'{"crayons": {"id": "1002", "name": "crayons", "datecreate": "150731"}}'

In [64]:
timech


Out[64]:
'140739'

In [ ]:


In [ ]:
ti

In [ ]:


In [19]:
#opnewp = open(prodirz + prodoadd, 'w')

##opnewp.write('0')

In [20]:
#new_key = RSA.generate(2048, e=65537)
#public_key = new_key.publickey().exportKey("PEM")
#private_key = new_key.exportKey("PEM")
#print private_key 
#sapriv = open(prodirc + '/' + prodoadd, 'w')
#sapriv.write(private_key)
#sapriv.close()

#print public_key 
#papriv =  open(prodirc + '/' +  prodoadd + '.pub', 'w')
#papriv.write(public_key)
#papriv.close()

In [21]:
#dict that has all the product details. When it was first
#created. Price. 
#amount sold. This value will be zero when a product is created
#but add 1 with productsell script. 
#Store amount sold data in dict
#or just a file called productname-amountsold.

In [ ]:


In [22]:
#opnewp.close()

In [23]:
#for prol in prolis:
#    print prol
#    adprod = open(prodirz + prol + '.meta', 'w')
#    adprod.write(

In [ ]:


In [24]:
#adprod = open(pro

In [ ]:


In [ ]:


In [ ]: