def updateSkuState(self, sku, token): user = self.validateToken(token) if 'error' in user: return user skudao = SkuDao() skudao.updateState(sku) return ResponseHelper.generateSuccessResponse(None)
def getAll(self, token): user = self.validateToken(token) if 'error' in user: return user skudao = SkuDao() skus = skudao.getAll(user) return ResponseHelper.generateSuccessResponse(skus)
def execute(self): print("*********** Price Automatically is executed ***********") skudao = SkuDao() skus = skudao.getAll() if (skus == None): return userDao = UserDao() user = userDao.getUser("token") for sku in skus: enemies = self.getEnemies(sku['link']) self.priceAlgorithm(enemies, user, sku)
def doUpdatePrice(self, sku, newSpecialPrice): sku['updated_at'] = int(round(time.time())) sku['special_price'] = newSpecialPrice # Update internal database skuDao = SkuDao() skuDao.update(sku) # Update external database userDao = UserDao() temporaryUser = userDao.getUser("token") lazadaSkuApi = LazadaSkuApi() lazadaProduct = lazadaSkuApi.updateProductSpecialPrice( sku, temporaryUser, newSpecialPrice) print("*********** Price Automatically do updated price ***********") print("Sku: ", sku['sku'], "/nnew special price: ", newSpecialPrice)
def insertSku(self, sku, token): user = self.validateToken(token) if 'error' in user: return user # Validate certain size skudao = SkuDao() userdao = UserDao() checkExistSku = skudao.checkExistSku(sku) if (checkExistSku > 0): return ResponseUtils.generateErrorResponse("You cannot add SKU already exist!!!") addedSize = skudao.getAddedSize(user['id']) certainSize = userdao.getCertainSize(user['id']) if (addedSize >= certainSize): return ResponseUtils.generateErrorResponse("You cannot add more SKU, please contact admin to improve your account!") # Validate SKU by product's data in database productDao = ProductDao() product, exception = productDao.getProductBySellerSku(user, sku) if exception != None: return ResponseUtils.generateErrorResponse(exception) # Add missing arguments and insert to our database sku['name'] = product['name'] sku['link'] = product['url'] sku['special_price'] = product['special_price'] skudao.insert(sku, user) return ResponseUtils.generateSuccessResponse()
def initialize(self): skudao = SkuDao() skudao.createTable() historyDao = HistoryDao() historyDao.createTable()
def insertSku(self, sku): skudao = SkuDao() skudao.insert(sku)
def updateSku(self, sku): skudao = SkuDao() return skudao.update(sku)
def getById(self, id): skudao = SkuDao() return skudao.getById(id)
def getAll(self, token): skudao = SkuDao() return skudao.getAll()
def deleteSku(self, sku): skudao = SkuDao() skudao.delete(sku)
import time import operator import requests import threading from time import sleep from lxml import html from database.sku_dao import SkuDao from lazada_api.lazada_sku_api import LazadaSkuApi from managers.sku_manager import SkuManager skudao = SkuDao() skuManager = SkuManager() lazadaSkuApi = LazadaSkuApi() class AutoPriceWorker(threading.Thread): def __init__(self, kwargs): threading.Thread.__init__(self) self.kwargs = kwargs def run(self): user = self.kwargs['user'] print('''*********** {}: is running ***********'''.format( user['lazada_user_name'])) skus = skudao.getActiveSku(user) if (skus == None): return for sku in skus: enemies = self.getEnemies(user, sku) self.priceAlgorithm(enemies, user, sku)