def filter_data_by_command_line_argument( infile, tag_str=None, date_str=None, ): indata = parse_file_content(infile) language_filter = BuiltIn().get_variable_value("${LANGUAGE_FILTER}") rows = [] tag_cloud = [] for row in indata: tag_match = True date_match = True row_tags = row["tags"].split(",") schedule = row["schedule"].lower() skip = False for x in row_tags: tag_cloud.append(x) if x in language_filter: skip = True if skip: continue if tag_str and tag_str not in row["tags"]: tag_match = False if date_str and date_str.lower() not in schedule: date_match = False if tag_match and date_match: rows.append(row) table = Tables().create_table( rows, columns=["name", "schedule", "description", "tags"]) Tables().write_table_to_csv( table, "sessions.csv", header=["name", "schedule", "description", "tags"]) counter = Counter(tag_cloud) return rows, counter
def read_worksheet_as_table(self, name=None, header=False, trim=True, start=None): """Read the content of a worksheet into a Table container. Allows sorting/filtering/manipulating using the ``RPA.Tables`` library. :param name: Name of worksheet to read :param header: If `True`, use the first row of the worksheet as headers for the rest of the rows. :param trim: Remove all empty rows from the end of the worksheet :param start: Row index to start reading data from (1-indexed) Examples: .. code-block:: robotframework Open Workbook orders.xlsx ${table}= Read Worksheet As Table header=True Close Workbook """ tables = Tables() sheet = self.read_worksheet(name, header, start) return tables.create_table(sheet, trim)
def read_worksheet_as_table(self, name=None, header=False, trim=True, start=None): """Read the content of a worksheet into a Table container. Allows sorting/filtering/manipulating using the `RPA.Tables` library. :param name: Name of worksheet to read :param header: If `True`, use the first row of the worksheet as headers for the rest of the rows. :param trim: Remove all empty rows from the end of the worksheet :param start: Row index to start reading data from (1-indexed) """ tables = Tables() sheet = self.read_worksheet(name, header, start) return tables.create_table(sheet, trim)
def _generate_table_from_SFDC_API_query(self, result, start=0, limit=0): records = (result["records"][start:] if limit == 0 else result["records"][start:start + limit]) if len(records) == 0: return Tables().create_table() cols = [k for k, v in self._get_values(records[0])] table = Tables().create_table(columns=cols) for row in records: values = self._get_values(row) table.append_row(row=dict(values)) return table
def get_orders(self, excel): files = Files() workbook = files.open_workbook(excel) rows = workbook.read_worksheet(header=True) tables = Tables() table = tables.create_table(rows) tables.filter_empty_rows(table) orders = [] for row in table: order = { "item": row.Item, "zip": int(row.Zip), "first_name": row[0].split()[0], "last_name": row[0].split()[1] } orders.append(order) return orders
def _process_tables(self, raw_tables): self.tables = {} for idx, t in raw_tables.items(): rows = {} for tid in t: row = self.cells[tid]["RowIndex"] col = self.cells[tid]["ColumnIndex"] val = self.cells[tid]["Content"] if row in rows.keys(): rows[row][col] = val else: rows[row] = {col: val} tables = Tables() data = [[rows[col][idx] for idx in sorted(rows[col])] for col in sorted(rows)] table = tables.create_table(data) self.tables[idx] = table
def control_room_start_fix_process(self, data, original): tables = Tables() excel = Files() google = Google() conflicts = [] updated_table = tables.export_table(original, with_index=True, as_list=False) for k in data.keys(): copyof_orig = copy.deepcopy(original) if "nameerror" in k: mid, _ = data[k].split(" - ") tables.filter_table_by_column(copyof_orig, "Account Id", "==", mid) row = tables.get_table_row(copyof_orig, 0) conflicts.append({"id": mid, "name": row["Name in SAP"]}) name_position = updated_table["Account Id"].index(mid) updated_table["Name OK in SFDC"][name_position] = "TRUE" if conflicts: self.control_room_run_process(CONTROL_ROOM_PROCESS_FIX_SFDC, conflicts) google.set_robocorp_vault(vault_name="googlecloud", vault_secret_key="credentials") google.init_drive(use_robocorp_vault=True) del updated_table["index"] excel.create_workbook(COMPARISON_EXCEL) excel.append_rows_to_worksheet(updated_table, header=True) excel.save_workbook() google.drive_upload_file(COMPARISON_EXCEL, GOOGLE_DRIVE_SYNC_FOLDER, overwrite=True)
def notebook_table(table, count: int = 20): """Display RPA.Table as IPython Markdown object in the notebook :param table: `RPA.Table` object to print """ # pylint: disable=C0415,E0611 from RPA.Tables import Tables # noqa if count: table = Tables().table_head(table, count=count) output = _get_table_output(table) if output: display(Markdown(output))
def notebook_table(table: Any, count: int = 20, columns=None): """Display RPA.Table or RPA.Table shaped data as IPython Markdown object in the notebook :param table: `RPA.Table` object to print :param count: How many rows of table to print :param columns: Names / headers of the table columns :param index: List of indices for table rows """ # pylint: disable=C0415,E0611 from RPA.Tables import Table, Tables # noqa table = Table(table, columns) if count: table = Tables().table_head(table, count=count) output = _get_table_output(table) if output: display(Markdown(output))
def read_worksheet_as_table(self, name=None, header=False, trim=True): """Read the content of a worksheet into a Table container. Allows sorting/filtering/manipulating using the `RPA.Tables` library. :param name: Name of worksheet to read :param header: If `True`, use the first row of the worksheet as headers for the rest of the rows. :param trim: Remove all empty rows from the end of the worksheet """ tables = Tables() sheet = self.read_worksheet(name, header) table = tables.create_table(sheet) if trim: tables.trim_empty_rows(table) tables.trim_column_names(table) return table
def _get_table_output(table): # pylint: disable=C0415,E0611 from RPA.Tables import Tables, Table # noqa output = "" try: if isinstance(table, Table): output = "<table class='rpafw-notebook-table'>" header = Tables().table_head(table, count=1) for row in header: output += "<tr>" for h, _ in row.items(): output += f"<th>{h}</th>" output += "</tr>" for row in table: output += "<tr>" for _, cell in row.items(): output += f"<td>{cell}</td>" output += "</tr>" output += "</table><br>" except ImportError: pass return None if output == "" else output
def library(): return Tables()
import os import emailer from RPA.Excel.Files import Files from RPA.Tables import Tables EMPLOYEES_EXCEL_PATH = os.environ["EMPLOYEES_EXCEL_PATH"] TRAININGS_EXCEL_PATH = os.environ["TRAININGS_EXCEL_PATH"] excel = Files() tables = Tables() def send_training_reminders(): employees = get_active_employees(EMPLOYEES_EXCEL_PATH) trainings = read_excel_as_table(TRAININGS_EXCEL_PATH) send_reminders(employees, trainings) def get_active_employees(excel_path): employees = read_excel_as_table(excel_path) tables.filter_table_by_column(employees, "Status", "==", "Active") tables.filter_table_by_column(employees, "Category", "==", "Employee") return employees def read_excel_as_table(excel_path): try: excel.open_workbook(excel_path) return excel.read_worksheet_as_table(header=True) finally: excel.close_workbook()