Beispiel #1
0
class ShopProductListHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        shopId = self.get_args("shop_id")
        page = self.get_args("page")
        pageSize = self.get_args("pageSize")
        if page is None or page == '':
            page = 1
        else:
            page = int(page)
        if pageSize is None or pageSize == '':
            pageSize = 20
        else:
            pageSize = int(pageSize)
        products = self.productDao.get_products_by_shop_id(shopId, page, pageSize)
        products = shop_list_to_json(products)
        productCount = self.productDao.get_products_count_by_shop_id(shopId)
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["products"] = products
        pagination = {}
        pagination["current_page"] = page
        pagination["size"] = productCount
        lastPage = (productCount + pageSize - 1) / pageSize;
        pagination["last_page"] = lastPage
        result["pagination"] = pagination
        pagination["pageSize"] = pageSize
        self.finish(result)
Beispiel #2
0
class ShopDataHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        shopId = self.get_args("shop_id")
        productsCount = self.productDao.get_products_count_by_shop_id(shopId)
        productSales = self.productDao.get_all_sales_by_shop_id(shopId)
        comments = self.productDao.get_comments_count_by_shop_id(shopId)
        if comments is None or comments == '':
            gc = 0
            mdc = 0
        else:
            gc = comments[0]
            mdc = comments[1]
        if productsCount is None or productsCount == '':
            productsCount = 0
        if productSales is None or productSales == '':
            productSales = 0
        else:
            productSales = productSales[0]
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["productsCount"] = str(productsCount)
        result["productSales"] = str(productSales)
        result["gccomments"] = str(gc)
        result["mdcomments"] = str(mdc)
        self.finish(result)
class DataEndCompa(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()
    def post(self, *args, **kwargs):
        taskId = self.get_args("task_id")
        page = self.get_args("page")
        if page is None or page == '' or page == 'undefined':
            page = 1
        else:
            page = int(page)
        pageSize = self.get_args("pageSize")
        if pageSize is None or pageSize == '' or pageSize == 'undefined':
            pageSize = 20
        else:
            pageSize = int(pageSize)
        product_date = self.productDao.get_data_date_by_task_id(taskId)
        for value in product_date:
            if value == '00000000':
                product_date.remove(value)
        minDate = product_date[0][0]
        length = len(product_date)
        maxDate = product_date[length - 1][0]
        result = {}
        check_end_list = []
        days = dateutils.diffDate(dateutils.str2date(minDate), dateutils.str2date(maxDate))
        #只是当前的参数,可修改。
        if days > 10:
            count = self.productDao.get_all_count_by_date_with_taskid(minDate, taskId)
            pagination = {}
            lastPage = count / pageSize + 1
            pagination.setdefault("size", pageSize)
            pagination.setdefault("current_page", page)
            pagination.setdefault("last_page", lastPage)
            product_end = self.productDao.get_data_by_date_with_taskid(maxDate, taskId, page, pageSize)
            product_end_all = self.productDao.get_all_data_by_date_with_taskid(minDate, taskId)
            for index, product in product_end:
                check_end_list["product_id"] = product.product_id
                check_end_list["product_name"] = product.product_name
                check_end_list["product_url"] = product.product_url
                for p_all in product_end_all:
                    if product.product_id == p_all.product_id:
                        continue
                    check_end_list["state"] = "2"
            result["status"] = 0
            result["message"] = "测试成功"
            result["start_date"] = minDate
            result["end_date"] = maxDate
            result["product_check_end"] = check_end_list
            result["pagination"] = pagination
        else:
            result["status"] = 1
            result["message"] = "没有可测试数据"
        self.finish(result)
Beispiel #4
0
class TaskDataHandler(AccessHandler):
    def initialize(self):
        self.taskDao = TaskDao()
        self.shopDao = ShopDao()
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        taskId = self.get_args("task_id")
        shopCount = self.shopDao.select_all_shop_by_task_id(taskId)
        productCount = self.productDao.get_all_products_by_taskid(taskId)
        productSales = self.productDao.get_sales_count_by_taskid(taskId)
        productMidPrice = self.productDao.get_mid_price_by_taskid(taskId)
        result = {}
        result["status"] = 0
        result["message"] = "更新成功"
        result["shopCount"] = shopCount
        result["productCount"] = productCount
        result["sales"] = productSales
        result["midPrice"] = productMidPrice
        self.finish(result)
class ProductDetailsHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        productId = self.get_args("product_id")
        product = self.productDao.get_product_by_id(productId)
        product = product_with_shop_to_dict(product)
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["product"] = product
        self.finish(result)
class ProductPriceHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        productId = self.get_args("product_id")
        prices = self.productDao.get_price_by_product_id(productId)
        plist = list(prices)
        xDate = []
        current_price = []
        original_price = []
        length = plist.__len__()
        if length > 0 and length <= 1:
            plist.append(plist[0])
            xDate.append(plist[0][2])
            xDate.append(plist[0][2])
            current_price.append(plist[0][0])
            current_price.append(plist[0][0])
            original_price.append(plist[0][1])
            original_price.append(plist[0][1])
        elif length > 6:
            minDate = plist[length - 1][2]
            maxDate = plist[0][2]
            xDate.append(minDate)
            current_price.append(plist[length - 1][0])
            original_price.append(plist[length - 1][1])
            data_list = plist
            data_list = data_list.pop(length - 1)
            data_list = data_list.pop(0)
            data_list = random.sample(data_list, 4)
            data_list.sort()
            for index in range(len(data_list)):
                xDate.append(data_list[index][2])
                current_price.append(data_list[index][0])
                original_price.append(data_list[index][1])
            original_price.append(plist[0][1])
            current_price.append(plist[0][0])
            xDate.append(maxDate)
        else:
            for index in range(len(plist)):
                xDate.append(plist[index][2])
                current_price.append(plist[index][0])
                original_price.append(plist[index][1])
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["xDate"] = xDate
        result["current_price"] = current_price
        result["original_price"] = original_price
        self.finish(result)
Beispiel #7
0
class IndexDataHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()
        self.shopDao = ShopDao()
        self.taskDao = TaskDao()

    def post(self):
        productData = self.productDao.get_all_product()
        shopData = self.shopDao.select_all_shop_count()
        taskData = self.taskDao.get_all_task_count()
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["productData"] = productData
        result["shopData"] = shopData
        result["taskData"] = taskData
        self.finish(result)
class ProductPopularHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        productId = self.get_args("product_id")
        populars = self.productDao.get_popular_by_product_id(productId)
        plist = list(populars)
        xDate = []
        populars_list = []
        length = plist.__len__()
        if length > 0 and length <= 1:
            xDate.append(plist[0][1])
            xDate.append(plist[0][1])
            populars_list.append(plist[0][0])
            populars_list.append(plist[0][0])
        elif length > 6:
            xDate.append(plist[length - 1][1])
            populars_list.append(plist[length - 1][0])
            data_list = plist
            data_list = data_list.pop(length - 1)
            data_list = data_list.pop(0)
            data_list = random.sample(data_list, 4)
            data_list.sort()
            for index in range(len(data_list)):
                xDate.append(plist[index][1])
                populars_list.append(plist[index][0])
            xDate.append(plist[0][1])
            populars_list.append(plist[0][0])
        else:
            for index in range(len(plist)):
                xDate.append(plist[index][1])
                populars_list.append(plist[index][0])
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["xDate"] = xDate
        result["populars"] = populars_list
        self.finish(result)
 def initialize(self):
     self.productDao = ProductDao()
Beispiel #10
0
 def initialize(self):
     self.taskDao = TaskDao()
     self.shopDao = ShopDao()
     self.productDao = ProductDao()
Beispiel #11
0
class ProductListHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        taskId = self.get_args("task_id")
        productName = self.get_args("product_name")
        minPrice = self.get_args("min_price")
        maxPrice = self.get_args("max_price")
        minComments = self.get_args("min_comments")
        maxComments = self.get_args("max_comments")
        minSales = self.get_args("min_sales")
        maxSales = self.get_args("max_sales")
        shopName = self.get_args("shop_name")
        shopArea = self.get_args("shop_area")
        shopType = self.get_args("shop_type")
        page = self.get_args("page")
        pageSize = self.get_args("pageSize")
        if productName is None or productName == 'null':
            productName = ''
        if minPrice is None or minPrice == 'null':
            minPrice = ''
        if maxPrice is None or maxPrice == 'null':
            maxPrice = ''
        if minComments is None or minComments == 'null':
            minComments = ''
        if maxComments is None or maxComments == 'null':
            maxComments = ''
        if minSales is None or minSales == 'null':
            minSales = ''
        if maxSales is None or maxSales == 'null':
            maxSales = ''
        if shopName is None or shopName == 'null':
            shopName = ''
        if shopArea is None or shopArea == 'null':
            shopArea = ''
        if shopType is None or shopType == 'null':
            shopType = ''
        if page is None or page == '':
            page = 1
        else:
            page = int(page)
        if pageSize is None or pageSize == '':
            pageSize = 20
        else:
            pageSize = int(pageSize)
        results = self.productDao.get_product_list_and_shop(
            taskId, productName, minPrice, maxPrice, minComments, maxComments,
            minSales, maxSales, shopName, shopArea, shopType, page, pageSize)
        results = product_list_to_dict(results)
        productCount = self.productDao.get_product_count_and_shop(
            taskId, productName, minPrice, maxPrice, minComments, maxComments,
            minSales, maxSales, shopName, shopArea, shopType)
        pagination = {}
        if productCount is None or productCount == '':
            pagination["current_page"] = page
            pagination["size"] = 0
            lastPage = 0
            pagination["last_page"] = lastPage
            pagination["pageSize"] = pageSize
        else:
            pagination["current_page"] = page
            pagination["size"] = productCount[0]
            lastPage = (productCount[0] + pageSize - 1) / pageSize
            pagination["last_page"] = lastPage
            pagination["pageSize"] = pageSize
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["products"] = results
        result["pagination"] = pagination
        self.finish(result)
Beispiel #12
0
class ProductCommentsHandler(AccessHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def post(self, *args, **kwargs):
        productId = self.get_args("product_id")
        commnets = self.productDao.get_comments_by_product_id(productId)
        clist = list(commnets)
        ##中差评
        md = []
        ##总的评论
        product_comments = []
        ##比例
        md_rate = []
        xDate = []
        length = clist.__len__()
        if length > 0 and length <= 1:
            clist.append(clist[0])
            xDate.append(clist[0][2])
            xDate.append(clist[0][2])
            md.append(clist[0][1])
            md.append(clist[0][1])
            product_comments.append(clist[0][0])
            product_comments.append(clist[0][0])
            md_rate.append(md_rate_fun(clist[0][0], clist[0][1]))
            md_rate.append(md_rate_fun(clist[0][0], clist[0][1]))
        elif length > 6:
            xDate.append(clist[length - 1][2])
            md.append(clist[length - 1][1])
            product_comments.append(clist[length - 1][0])
            md_rate.append(
                md_rate_fun(clist[length - 1][0], clist[length - 1][1]))
            data_list = clist
            data_list = data_list.pop(length - 1)
            data_list = data_list.pop(0)
            data_list = random.sample(data_list, 4)
            data_list.sort()
            for index in range(len(data_list)):
                xDate.append(data_list[index][2])
                product_comments.append(data_list[index][0])
                md.append(data_list[index][1])
                md_rate.append(
                    md_rate_fun(data_list[index][0], data_list[index][1]))
            xDate.append(clist[0][2])
            md.append(clist[0][1])
            product_comments.append(clist[0][0])
            md_rate.append(md_rate_fun(clist[0][0], clist[0][1]))
        else:
            for index in range(len(clist)):
                xDate.append(clist[index][2])
                md.append(clist[index][1])
                product_comments.append(clist[index][0])
                md_rate.append(md_rate_fun(clist[index][0], clist[index][1]))
        result = {}
        result["status"] = 0
        result["message"] = "获取数据成功"
        result["xDate"] = xDate
        result["product_comments"] = product_comments
        result["md"] = md
        result["md_rate"] = md_rate
        self.finish(result)
Beispiel #13
0
class ProductExportHandler(BaseHandler):
    def initialize(self):
        self.productDao = ProductDao()

    def get(self, *args, **kwargs):
        taskId = self.get_args("task_id")
        productName = self.get_args("product_name")
        minPrice = self.get_args("min_price")
        maxPrice = self.get_args("max_price")
        minComments = self.get_args("min_comments")
        maxComments = self.get_args("max_comments")
        minSales = self.get_args("min_sales")
        maxSales = self.get_args("max_sales")
        shopName = self.get_args("shop_name")
        shopArea = self.get_args("shop_area")
        shopType = self.get_args("shop_type")
        page = self.get_args("page")
        pageSize = self.get_args("pageSize")
        if taskId is None or taskId == 'null':
            taskId = ''
        if productName is None or productName == 'null':
            productName = ''
        if minPrice is None or minPrice == 'null':
            minPrice = ''
        if maxPrice is None or maxPrice == 'null':
            maxPrice = ''
        if minComments is None or minComments == 'null':
            minComments = ''
        if maxComments is None or maxComments == 'null':
            maxComments = ''
        if minSales is None or minSales == 'null':
            minSales = ''
        if maxSales is None or maxSales == 'null':
            maxSales = ''
        if shopName is None or shopName == 'null':
            shopName = ''
        if shopArea is None or shopArea == 'null':
            shopArea = ''
        if shopType is None or shopType == 'null':
            shopType = ''
        if page is not None:
            page = int(page)
        else:
            page = 1
        if pageSize is not None:
            pageSize = int(pageSize)
        else:
            pageSize = 20
        pageSize = page * pageSize
        results = self.productDao.get_product_list_and_shop_all(
            taskId, productName, minPrice, maxPrice, minComments, maxComments,
            minSales, maxSales, shopName, shopArea, shopType)
        workbook = xlwt.Workbook(encoding='utf-8')
        font = xlwt.Font()
        font.name = 'SimSu'
        sheet = workbook.add_sheet('导出产品数据')
        sheet.write(0, 0, '淘宝旺旺')
        sheet.write(0, 1, '产品名')
        sheet.write(0, 2, '产品链接')
        sheet.write(0, 3, '店铺名称')
        sheet.write(0, 4, '店铺链接')
        sheet.write(0, 5, '价格')
        sheet.write(0, 6, '销量')
        sheet.write(0, 7, '库存')
        sheet.write(0, 8, '所在地')
        row = 1
        for data in results:
            sheet.write(row, 0, data.shop_boss_tb)
            sheet.write(row, 1, data.product_name)
            sheet.write(row, 2, data.product_url)
            sheet.write(row, 3, data.shop_name)
            sheet.write(row, 4, data.shop_url)
            sheet.write(row, 5, data.current_price)
            sheet.write(row, 6, data.product_sales_count)
            sheet.write(row, 7, data.product_stock)
            sheet.write(row, 8, data.shop_area)
            row += 1
        self.set_header('Content-Type', 'application/x-xls')
        filename = datetime.datetime.now().strftime("%Y-%m-%d") + ".xls"
        self.set_header('Content-Disposition',
                        'attachment; filename=' + filename + '')
        sio = StringIO.StringIO()
        workbook.save(sio)
        self.write(sio.getvalue())
        self.finish()