Product Config
Product Configure
In [49]:
import os
import configparser
import getpass
In [50]:
config = configparser.RawConfigParser()
In [51]:
osuser = getpass.getuser()
In [51]:
In [51]:
In [52]:
osuser
Out[52]:
In [53]:
homdir = ('/home/' + osuser + '/sellcoffee/')
In [54]:
homdir
Out[54]:
In [55]:
confighdir = homdir + ('config.cfg')
In [56]:
confighdir
Out[56]:
In [57]:
config.read(confighdir)
Out[57]:
In [58]:
#config.add_section
In [59]:
prodirz = ('/home/wcmckee/sellcoffee/products/')
In [60]:
#Each shopper has a username, inside that username is a product
#list.
In [61]:
prodos = os.listdir(prodirz)
In [62]:
prodos
#Create .cfg file for each item in list.
#Create one .cfg file that contains each product section,
#id, price, etc are in each product section.
Out[62]:
In [63]:
for prod in prodos:
#print prod
#print os.listdir(prodirz + prod)
prodop = open(prodirz + prod + '/' + prod + '-id', 'r')
print prodop.read()
prodop.close()
In [63]:
#id isnt being written to config file. sort it out.
In [68]:
for prod in prodos:
print prod
config.add_section(prod)
prodop = open(prodirz + prod + '/' + prod + '-id', 'r')
prodread = prodop.read()
config.set(prod, 'id', prodread)
#print prodop.read()
prodop.close()
In [69]:
with open(confighdir, 'wb') as configfile:
config.write(configfile)
In [67]:
In [ ]: