def main(queue, countrycode): if not os.path.isfile(GlobalTools.getExcelFile(countrycode)): # messagebox.showerror("error", u"请将uk.xls放到和amazon.exe相同目录下") queue.put(u"ERROR:请将" + countrycode + u".xls放到和amazon.exe相同目录下") exit(0) products = [] rb = xlrd.open_workbook(GlobalTools.getExcelFile(countrycode)) try: sheet = rb.sheet_by_name("asin") count = sheet.nrows for i in range(0, count): print(sheet.cell_value(i, 0)) products.append(sheet.cell_value(i, 0)) except: # messagebox.showerror("error", u"uk.xls中必须包含名字为asin的sheet") queue.put(u"ERROR:请将" + countrycode + u".xls放到和amazon.exe相同目录下") exit(0) print("copy") wb = copy(rb) sheet = wb.add_sheet( time.strftime(u"%m-%d_%H-%M", time.localtime(time.time()))) # 写头部标题: tableheaders = GlobalTools.get_table_header() row = 0 col = 0 for item in tableheaders: sheet.write(row, col, item) col += 1 pool = multiprocessing.Pool(processes=5) currrow = 1 results = [] for product in products: results.append( pool.apply_async(fun, ( queue, product, countrycode, currrow, sheet, ))) currrow += 1 pool.close() pool.join() # for res in results: # # try: # print res.get() # # except: # # pass for result in results: try: row = result.get() currrow = row[0] print("currrow:" + str(currrow)) col = 0 for i in range(1, len(row)): sheet.write(currrow, col, row[i]) col += 1 except: pass try: wb.save(GlobalTools.getExcelFile(countrycode)) except: queue.put(u"ERROR:保存文件失败,运行时,请不要打开站点对应的xls文件") exit(0) queue.put("finish.")
def main(queue): if not os.path.isfile(GlobalTools.getExcelFile("fba")): queue.put("ERROR:"+u"请将fba.xls放到和amazon.exe相同目录下") exit(0) productlinks = [] rb = xlrd.open_workbook(GlobalTools.getExcelFile("fba")) try: sheet = rb.sheet_by_index(0) count = sheet.nrows for i in range(0,count): print(sheet.cell_value(i,0)) productlinks.append(sheet.cell_value(i,0)) except: queue.put("ERROR:" + u"请保证文件包含商品链接") exit(0) wb = copy(rb) sheet = wb.add_sheet(time.strftime(u"%m-%d_%H-%M",time.localtime(time.time()))) pool = multiprocessing.Pool(processes=5) currrow = 0 results = [] for link in productlinks: if link.strip() == "": currrow+=1 continue countrycode = link.split("amazon.")[1].split(".")[-1].split('/')[0] results.append(pool.apply_async(fun,(queue,link,currrow,countrycode))) currrow+=1 pool.close() pool.join() # for res in results: # # try: # print res.get() # # except: # # pass # print "finish." tmpresult = [] for result in results: try: row = result.get() tmpresult.append(row) currrow = row[0] print("currrow:"+str(currrow)) col = 0 for i in range(1,len(row)): sheet.write(currrow, col, row[i]) col+=1 except: pass try: wb.save(GlobalTools.getExcelFile("fba")) except: tmp = open("./tmp.txt","w+") for row in tmpresult: tmp.write(str(row)+"\n") queue.put("ERROR:"+u"保存文件失败,运行时,请不要打开fba.xls文件") queue.put("finish.")