def get_all_column(self, sheet, which_content): """which_content should be the cell""" content_coordinate = pasu.get_coordinate(which_content) if which_content.value == 'bullet_point1': bullet_points_dict = { 'first_column': pasu.get_column_except_none_cell(sheet, content_coordinate[0], content_coordinate[1] + 0), 'second_column': pasu.get_column_except_none_cell(sheet, content_coordinate[0], content_coordinate[1] + 1), 'third_column': pasu.get_column_except_none_cell(sheet, content_coordinate[0], content_coordinate[1] + 2), 'fourth_column': pasu.get_column_except_none_cell(sheet, content_coordinate[0], content_coordinate[1] + 3), 'fifth_column': pasu.get_column_except_none_cell(sheet, content_coordinate[0], content_coordinate[1] + 4) } full_bp_list = [] for key, value in bullet_points_dict.items(): content_list = \ [self.add_cor(each_cell) for each_cell in value] full_bp_list.append(self.htm_warp(content_list)) return '\n'.join(full_bp_list) content_list = pasu.get_column_except_none_cell( sheet, content_coordinate[0], content_coordinate[1]) content_list = \ [self.add_cor(each_cell).replace('<br>', BR_PATTERN) for each_cell in content_list] return self.htm_warp(content_list)
def process_model_number(self): model_coordinate = pasu.get_coordinate(self.model_cell) model_number = ''.join(random.sample(ALPHABET, 1)) + str( random.randint(10, 99)) pasu.process_info(self.sheet, model_coordinate, model_number, column_offset=-7)
def process_part_number(self): part_number_coordinate = pasu.get_coordinate(self.part_number_cell) part_number = ''.join(random.sample(ALPHABET, 2)) + '-' + str( random.randint(100, 999)) pasu.process_info(self.sheet, part_number_coordinate, part_number, column_offset=-1)
def process_title(self): item_name_coordinate = pasu.get_coordinate(self.item_name_cell) title_list = pasu.get_column_except_none_cell(self.sheet, item_name_coordinate[0], item_name_coordinate[1]) self.all_titles = [each_title.value for each_title in title_list] for index, title in enumerate(title_list): title_list[index].value = pasu.process_item_name(title.value)
def process_keywords(self, keywords: str): if keywords == SECRET_CODE: # 获取所有的标题 item_name_coordinate = pasu.get_coordinate(self.item_name_cell) title_list = pasu.get_column_except_none_cell( self.sheet, item_name_coordinate[0], item_name_coordinate[1]) self.all_titles = [each_title.value for each_title in title_list] # 用标题高频词处理关键字 processed_keywords = ' '.join( pasu.high_frequent_words(self.all_titles))[:KW_TRIMMER] if pasu.cjk_detect(processed_keywords) is not None: processed_keywords = processed_keywords[:50] processed_keywords = processed_keywords.replace(' ', ' ') # 处理关键词 keywords_coordinate = coordinate_to_tuple( str(self.keywords_cell).split('.')[-1][:-1]) pasu.process_info(self.sheet, keywords_coordinate, processed_keywords) else: keywords_coordinate = coordinate_to_tuple( str(self.keywords_cell).split('.')[-1][:-1]) pasu.process_info(self.sheet, keywords_coordinate, keywords)
def get_content_list(sheet, cell_name: str) -> list: cell = find_cell(sheet, cell_name) cell_coordinate = pasu.get_coordinate(cell) content_list = pasu.get_column_except_none_cell(sheet, cell_coordinate[0], cell_coordinate[1]) return content_list
def main(self): files = self.find_all_txt_file() self.get_langs_and_langs_dict(files) oc_file = pasu.index_files(ui_msg='输入 <表格文件> 所在的路径:', which_file_msg='请选择原始表格文件:')[-1] original_wb = openpyxl.load_workbook(str(oc_file)) original_sheet = original_wb.get_sheet_by_name('sheet1') # 获取价格和节点的成员函数 def get_node_price_list(): _new_wb = openpyxl.load_workbook(str(oc_file)) _new_sheet = _new_wb.get_sheet_by_name('sheet1') _node_list = get_content_list(_new_sheet, 'recommended_browse_nodes') _price_list = get_content_list(_new_sheet, 'standard_price') _price_list = [ each_cell for each_cell in _price_list if each_cell.value != '' ] return _node_list, _price_list, _new_wb, _new_sheet if check_if_the_same_day(get_time_stamp()): excr_node = {} excr_node_result = asking_for_excr_node_input() excr_node_result = excr_node_result.split('\n') excr_node_result = [ each_line for each_line in excr_node_result if each_line != '' or each_line != ':' ] for each_line in excr_node_result: excr_node[each_line.split(':')[0].strip()] = \ EXCHANGE_RATE_NODE[0]+str(each_line.split(':')[-1].strip())+EXCHANGE_RATE_NODE[1] with open('excr_node.py', 'w', encoding='utf-8') as t: t.write('excr_node = ' + str(excr_node)) with open('_time_stamp_for_excr_node.py', 'w', encoding='utf-8') as t: t.write( 'time_stamp = ' + f'"{datetime.datetime.strftime(datetime.datetime.now(), "%Y, %m, %d, %I, %M, %S")}"' ) # 处理文本文件 for lang, file_list in self.langs_dict.items(): import excr_node template = { key: value for key, value in excr_node.excr_node.items() if key != '' } for each_file in file_list: out_file_name = self.directory + '\\' + lang + '_' + str( oc_file).split('\\')[-1] print(f'正在处理 {out_file_name}') if excr_node.excr_node is not None: for lang_excr_node, _excr_node in template.items(): if lang_excr_node in each_file.split('\\')[-1]: line_prepender(each_file, _excr_node) content = open(each_file, encoding='utf-8').read() content_list = content.split('\n') content_list = [ each_line for each_line in content_list if each_line != '' ] content_list = [ each_line for each_line in content_list if SEPARATOR in each_line ] for each_content in content_list: try: if len(each_content.split(SEPARATOR)[0]) > 9: continue each_content = str(each_content).split(SEPARATOR) row = int(each_content[0].strip()[1:-1].replace( '、', ',').split(',')[0]) col = int(each_content[0].strip()[1:-1].replace( '、', ',').split(',')[1]) original_sheet.cell(row, col).value = each_content[-1].strip().replace(BR_PATTERN, ' <br> ')\ .replace('$$ $', ' <br> ').replace('$ $$', ' <br> ') except Exception as e: print(f'{each_file} 中的内容: {each_content} 发生了错误 {e}') continue if EXCHANGE_RATE_NODE[0] not in content: input(f'\n文本文件: ({each_file}) 当中没有标明汇率和节点,请检查文件(回车继续)') continue elif EXCHANGE_RATE_NODE[0] in content: search_result = re.search( re.compile(r'(?<=!!\[).+(?=]!!)'), content) if search_result is None: continue exchange_rate, node = str( re.search(re.compile(r'(?<=!!\[).+(?=]!!)'), content)[0]).split(',') node_list, price_list, new_wb, new_sheet = get_node_price_list( ) for each_node in node_list: row, col = pasu.get_coordinate(each_node) original_sheet.cell( int(row), int(col)).value = str(node).strip() for each_price in price_list: row, col = pasu.get_coordinate(each_price) original_sheet.cell(int(row), int(col)).value = \ self.calculate_time_exchange_rate(each_price, exchange_rate) print(f'\n当前的语言: {lang}') print(f'当前使用的节点:{node}') print(f'当前使用的汇率:{exchange_rate}') else: class NoExchangeNodeError(Exception): pass raise NoExchangeNodeError('No exchange rate and node') original_wb.save(out_file_name) pasu.back_to_main_menu(enter_quit=True)
def process_ship_time(self): fulfillment_latency_coordinate = pasu.get_coordinate( self.fulfillment_latency) pasu.process_info(self.sheet, fulfillment_latency_coordinate, 3)
def process_update_delete(self, _ui: str): update_coordinate = pasu.get_coordinate(self.update_delete) pasu.process_info(self.sheet, update_coordinate, _ui)
def process_node(self, node): node_coordinate = pasu.get_coordinate(self.node_cell) pasu.process_info(self.sheet, node_coordinate, node)
def process_price(self, lowest_price: int): price_coordinate = pasu.get_coordinate(self.price_cell) pasu.process_price(self.sheet, price_coordinate, lowest_price, self.current_file)
def process_bulletpoints(self): bullet_point_coordinate = pasu.get_coordinate(self.bullet_point_cell) pasu.process_bulletpoints(self.sheet, bullet_point_coordinate)
def process_description(self): description_coordinate = pasu.get_coordinate(self.description) pasu.process_description(self.sheet, description_coordinate)