def SubTask(self, driver, TaskInfo): Task = AmazonFunction(driver, TaskInfo) Task.speed = randint(100, 160) if not Task.login(): return False time.sleep(5) if not Task.CleanCart(): return False if not Task.SetAddress(): return False for asin in TaskInfo['asins']: Task.FunctionInfo['asin'] = asin Task.FunctionInfo.update(parseinfo.ProductFrame.loc[ Task.FunctionInfo['asin']].to_dict()) Task.FunctionInfo['lowprice'] = str( round((float(Task.FunctionInfo['buyboxprice']) - 0.01), 2)) Task.FunctionInfo['highprice'] = str( round((float(Task.FunctionInfo['buyboxprice']) + 0.01), 2)) #Task.FunctionInfo['lowprice'] = Task.FunctionInfo['buyboxprice'] #Task.FunctionInfo['highprice'] = Task.FunctionInfo['buyboxprice'] if not Task.SearchProduct(): print('Search production fail...') # Fatal error if not found in any page TBD TaskInfo['errorcode'] = 'SearchFail' TaskInfo['status'] = False return False if not Task.AddCart(): print('Add cart fail...') # Fatal error if not found TBD return False return True
def SubTask(self, driver, TaskInfo): TaskInfo['lowprice'] = '0' TaskInfo['highprice'] = '0' self.TaskName = TaskInfo['asin'] self.start_time = datetime.now() TaskInfo['keyword'] = random.sample(TaskInfo['keywords'], 1)[0] print('start info:::' + TaskInfo['asin'] + ' keyword: ' + TaskInfo['keyword']) Task = AmazonFunction(driver, TaskInfo) try: Task.driver.get('https://www.amazon.com/') except: pass try: Task.driver.maximize_window() except: print('Set full screen fail!') ProductionUrl = Task.SearchProduct() if not ProductionUrl: return False if not Task.ViewAllPage(): return False if not Task.view_reviewer(): return False if not Task.add_to_cart(): return False Task.back_to_page(ProductionUrl) while Task.stay_time() < Task.min_view_time: Task.speed = randint(20, 60) if not Task.view_all(): return False Task.back_to_page(ProductionUrl) self.TaskLog(TaskInfo) if int(TaskInfo['sections']) != '0': self.PushRetryQueue(TaskInfo) TaskInfo['sections'] = str(int(TaskInfo['sections']) - 1)