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 [22]:
import os
import time
import datetime
import json
import getpass
import arrow
#import satchless
#from satchless.item import ItemLine
#from TwitterFollowBot import TwitterBot
#from passlib.hash import pbkdf2_sha256
#import crypt, getpass, spwd
#from Crypto.PublicKey import RSA
#import crypto
#import rsa
In [ ]:
In [5]:
myusr = getpass.getuser()
In [6]:
#brotwe = TwitterBot('/home/{}/github/wcmckee-notebook/config.txt'.format(myusr))
In [7]:
yearz = time.strftime("%y", time.gmtime())
monthz = time.strftime("%m", time.gmtime())
dayz = time.strftime("%d", time.gmtime())
In [8]:
datez = yearz + monthz + dayz
In [9]:
prodirz = ('/home/{}/sellcoffee/posts/'.format(myusr))
In [11]:
prolis = os.listdir(prodirz)
In [15]:
print(prolis)
In [13]:
prodoadd = input('Name of product to add: ')
In [16]:
priceofit = input('Cost in NZD: ')
In [17]:
amoun = input('Amount to stock: ')
In [18]:
#class Shrubberies(ItemLine):
# def __init__(self, qty): self.qty = qty
# def get_quantity(self): return self.qty
# def get_price_per_item(self): return prices.Price(int(priceofit), currency='NZD')
#shrubberies = Shrubberies(int(amoun))
#shrubberies.get_total()
In [19]:
#shrubberies.qty
In [56]:
#shrubberies.get_price_per_item()
Out[56]:
In [69]:
#prodirz + prodoadd
Out[69]:
In [23]:
raw = arrow.now()
yraw = raw.strftime("%Y")
mntaw = raw.strftime("%m")
dytaw = raw.strftime("%d")
fulda = yraw + '/' + mntaw + '/' + dytaw
fultim = fulda + ' ' + raw.strftime('%H:%M:%S')
In [ ]:
In [28]:
with open(prodirz + prodoadd + '.rst', 'w') as oprod:
oprod.write(prodoadd + '\n\nprice: ' + priceofit + '\n\ntotal stock: ' + amoun)
#print(oprod)
In [25]:
with open(prodirz + prodoadd + '.meta', 'w') as daympo:
daympo.write('.. title: {} \n.. slug: {} \n.. date: {} \n.. author: {}'.format(prodoadd, prodoadd, fultim, myusr))
In [36]:
prodirc = (prodirz + prodoadd)
In [38]:
prodirc
Out[38]:
In [37]:
#os.mkdir(prodirc)
In [39]:
#opmeta = open(prodirc + '/' + prodoadd + '-amount', 'w')
#opmeta.write('0')
#opmeta.close()
In [40]:
opforc = open(prodirc + prodoadd + 'index.json', 'w')
In [41]:
dicprod = dict()
In [42]:
dicprod
Out[42]:
In [43]:
#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 [69]:
#switching to folders for each product. Inside folder has rsa
#and rsa.public.
In [70]:
dicprod.update({'name' : prodoadd})
dicprod.update({'id' : str(newids)})
dicprod.update({'datecreate' : datez})
In [71]:
adtwez = ('Added ' + prodoadd + ' id ' + str(newids))
In [72]:
#brotwe
Out[72]:
In [70]:
#adtwez
In [74]:
#brotwe.auto_rt('#gamedev', count=1)
In [ ]:
In [71]:
#brotwe.send_tweet(adtwez)
In [ ]:
In [72]:
tigm = time.strftime("%H %M %S", time.gmtime())
In [73]:
timech =tigm.replace(' ', '')
In [74]:
dicprod.update({'timecreate' : timech})
In [ ]:
In [75]:
dicprod
Out[75]:
In [76]:
prodoaddz = dict()
In [77]:
prodoaddz.update({prodoadd : dicprod})
In [78]:
prodoaddz
Out[78]:
In [79]:
json.dumps(prodoaddz)
Out[79]:
In [19]:
#opnewp = open(prodirz + prodoadd, 'w')
##opnewp.write('0')
In [ ]:
In [ ]:
In [112]:
#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 [ ]:
In [ ]:
In [ ]:
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 [24]:
#adprod = open(pro