Example #1
0
def industries():
    brand = Brand()
    industry_list = brand.get_industries()
    react_industry_list = []
    for i in industry_list:
        react_industry_list.append({"value": i, "label": i})
    return jsonify({"industry_list": react_industry_list})
Example #2
0
def getBrandSpecs(brand_name, sim_settings):
    if brand_name == None:
        return None
    else:
        this_brand = Brand(
            brand_name, sim_settings.brand_dictionary[brand_name]["cost"],
            sim_settings.brand_dictionary[brand_name]["alcohol"])
        return this_brand
 def augmentDataByBrand(self, products, brand_filename, out_filename):
     b = Brand(brand_filename)
     # for each category in categories:
     # need the titles and brands of each category
     newproducts = pd.DataFrame(columns=self.columns +
                                ["IsClear", "IsConcise"])
     for c in b.getCategories():
         titles = products.loc[products['Category'] == c]
         tc_title = TextCorpus(titles['Title'].tolist())
         newtitles = tc_title.permute(b.getTopBrandsByCategory(c, top_n=5))
         for i, (index, row) in enumerate(
                 titles.filter(self.columns + ["IsClear", "IsConcise"],
                               axis=1).iterrows()):
             for j, newtitle in enumerate(newtitles[i]):
                 newrow = row.copy()
                 newrow['Title'] = newtitle
                 newrow['SkuId'] = row['SkuId'] + '_' + str(j)
                 newproducts = newproducts.append(newrow, ignore_index=True)
     newproducts.to_csv(out_filename,
                        header=True,
                        index=False,
                        encoding='utf-8')
Example #4
0
def feed():
    print(request.get_json())
    data = request.get_json()
    brand = Brand(brand_name=data["brand_name"], industry=data["industry"])
    brand.prep_db()
    brand.make_file()
    run()
    return data
Example #5
0
 def __init__(self):
   Controler.__init__(self)
   self._brand = Brand()
Example #6
0
class Product(Controler):
  def __init__(self):
    Controler.__init__(self)
    self._brand = Brand()

  def menu(self):
    while True:
      print " [0] Exit"
      print " [1] Add Product"
      print " [2] Del Product"
      print " [3] List Product"
      print " [4] Search Product"
      print " [5] Edit Product" 
      print " [6] Increment Product Count"
      print " [7] Decrement Product Count"
      print " [8] Manage Brand"
      print

      choice = self._input_int(" Your choise: ")
      print

      if choice == 0:
        return
      if choice == 1:
        self.add()
      if choice == 2:
        self.delete()
      elif choice == 3:
        self.list()
      elif choice == 4:
        self.search()
      elif choice == 5:
        self.edit()
      elif choice == 6:
        self.count_incr()
      elif choice == 7:
        self.count_decr()
      elif choice == 8:
        self._brand.menu()
      else:
        print "choice not understood, try again."


  def add(self):
    brand_dao = dao.Brand()
    brand_id = -1
    while brand_dao.exists_by_id(brand_id) is False:
      brand_id = self._input_num_or_list(self._brand.list, "brand_id (or l=list): ")
    
    product = models.Product()
    product._brand = brand_dao.get_by_id(brand_id)
    product._name = self._input("product_name: ")
    product._desc = self._input("product_desc: ")
    product._count = self._input_int("product_count: ")

    product_dao = dao.Product()
    product_dao.add(product)

    print

  def delete(self):
    product_id = self._input_num_or_list(self.list, "product_id (or l=list): ")
    product_dao = dao.Product()
    product_dao.delete_by_id(product_id)

  def edit(self):
    product_id = self._input_num_or_list(self.list, "product_id (or l=list): ")
    product_dao = dao.Product()
    product = product_dao.get_by_id(product_id)

    product._name = self._input_with_default(product._name, "product_name: ")
    product._desc = self._input_with_default(product._desc, "product_desc: ")
    product._count = int(self._input_with_default(product._count, "product_count: "))

    product_dao.update(product)

  def count_incr(self):
    product_id = self._input_num_or_list(self.list, "product_id (or l=list): ")
    product_dao = dao.Product()
    product_dao.count_incr(product_id)


  def count_decr(self):
    product_id = self._input_num_or_list(self.list, "product_id (or l=list): ")
    product_dao = dao.Product()
    product_dao.count_decr(product_id)

  def list(self):
    product_dao = dao.Product()
    product_view = views.console.Product()

    list = product_dao.get_list()
    product_view.show_list(list)

  def search(self):
    product_name = self._input("product_name: ")
    product_dao = dao.Product()
    product_view = views.console.Product()

    list = product_dao.search(product_name)
    product_view.show_list(list)
Example #7
0
cellar.InitById(str(cellar.Print()["_id"]))

print "rename : {}".format(cellar.Rename("otro nombre"))
print "list : {}".format(json_util.dumps(Cellar.GetAllCellars()))
#print "remove : {}".format(cellar.Remove())

print "\n\n"

####################################
########### brand.py ###############
####################################

print "testing brands"

brand = Brand()
brand.name = "giani"

print "save : {}".format(brand.Save())
print "list : {}".format(brand.GetAllBrands())

print "\n\n"

####################################
########### category.py ############
####################################

print "testing category"

category = Category()
category.parent = ""
Example #8
0
 def brand(self):
     return Brand.find_by("id", self.brand_id)
Example #9
0
 def __init__(self):
     core.Dao.__init__(self)
     self._brand_dao = Brand()
Example #10
0
class Product(core.Dao):
    def __init__(self):
        core.Dao.__init__(self)
        self._brand_dao = Brand()

    def _make_list(self, cursor):

        list = []
        for row in cursor.fetchall():
            product = models.Product(
                product_id=row[0],
                brand=self._brand_dao.get_by_id(row[1]),
                product_name=row[2],
                product_desc=row[3],
                product_count=row[4],
            )
            list.append(product)

        return list

    def add(self, product):
        query = """INSERT INTO product (
                 brand_id, product_name, product_desc,
                 product_count
               ) VALUES (
                 %(product_brand_id)s, %(product_name)s, %(product_desc)s, %(product_count)s
               );
             """

        params = {
            "product_brand_id": product._brand._id,
            "product_name": product._name,
            "product_desc": product._desc,
            "product_count": product._count,
        }

        cur = self._sql._connect.cursor()
        cur.execute(query, params)

        cur.close()

    def del_by_id(self, product_id):
        query = "DELETE FROM product WHERE product_id = %(product_id)s;"

        cur = self._sql._connect.cursor()
        cur.execute(query, {"product_id": product_id})
        cur.close()

    def del_by_name(self, product_name):
        query = "DELETE FROM product WHERE product_name = %(product_name)s;"

        cur = self._sql._connect.cursor()
        cur.execute(query, {"product_name": product_name})
        cur.close()

    def get_by_id(self, product_id):
        query = """SELECT
                 brand_id, product_name, product_desc, product_count
               FROM
                 product
               WHERE
                 product_id = %(product_id)s;"""

        cur = self._sql._connect.cursor()
        cur.execute(query, {"product_id": product_id})

        product = None
        if cur.rowcount == 1:
            row = cur.fetchone()
            product = models.Product(
                product_id=product_id,
                brand=self._brand_dao.get_by_id(row[0]),
                product_name=row[1],
                product_desc=row[2],
                product_count=row[3],
            )

        cur.close()
        return product

    def get_by_name(self, product_name):
        query = """SELECT
                 product_id, brand_id, product_desc, product_count
               FROM
                 product
               WHERE
                 product_name = %(product_name)s;"""

        cur = self._sql._connect.cursor()
        cur.execute(query, {"product_name": product_name})

        product = None
        if cur.rowcount == 1:
            row = cur.fetchone()
            product = models.Product(
                product_id=row[0],
                brand=self._brand_dao.get_by_id(row[1]),
                product_name=product_name,
                product_desc=row[2],
                product_count=row[3],
            )

        cur.close()
        return product

    def get_list(self):
        query = """SELECT 
                 product_id, brand_id, product_name, product_desc,
                 product_count
               FROM product;"""

        cur = self._sql._connect.cursor()
        cur.execute(query)
        list = self._make_list(cur)
        cur.close()

        return list

    def get_list_by_brand_name(self, brand_name):
        query = """SELECT 
                 product_id, brand_id, product_name, product_desc,
                 product_count
               FROM 
                product NATURAL JOIN brand
               WHERE
                brand_name = %(brand_name)s;"""

        cur = self._sql._connect.cursor()
        cur.execute(query, {"brand_name": brand_name})
        list = self._make_list(cur)
        cur.close()

        return list

    def update(self, product):
        query = """UPDATE 
                product
               SET
                brand_id = %(brand_id)s,
                product_name = %(product_name)s,
                product_desc = %(product_desc)s,
                product_count = %(product_count)s
               WHERE
                 product_id = %(product_id)s;"""

        params = {
            "brand_id": product._brand._id,
            "product_name": product._name,
            "product_desc": product._desc,
            "product_count": product._count,
            "product_id": product._id,
        }

        cur = self._sql._connect.cursor()
        cur.execute(query, params)
        cur.close()

    def count_incr(self, product_id):
        query = """UPDATE
                 product 
               SET
                 product_count = product_count + 1
               WHERE
                 product_id = %(product_id)s;"""

        cur = self._sql._connect.cursor()
        cur.execute(query, {"product_id": product_id})
        cur.close()

    def count_decr(self, product_id):
        query = """UPDATE
                 product 
               SET
                 product_count = product_count - 1
               WHERE
                 product_id = %(product_id)s;"""

        cur = self._sql._connect.cursor()
        cur.execute(query, {"product_id": product_id})
        cur.close()

    def search(self, search):
        query = """SELECT
                 product_id, brand_id, product_name, product_desc,
                 product_count
               FROM
                 product
               WHERE
                 product_name LIKE %(search)s;
            """

        cur = self._sql._connect.cursor()
        cur.execute(query, {"search": search})
        list = self._make_list(cur)
        cur.close()

        return list
Example #11
0
 def create_brand(brand):
     return Brand(brand[0], brand[1])
Example #12
0
 def brand(self):
     return Brand.find_by("id", self.brand_id)