Ejemplo n.º 1
0
    def apply_to_sheet(self, worksheet: gspread.Worksheet):
        """
        Update the specified Google Sheet worksheet by altering the row
        corresponding to this update's edited message.
        """
        # Find existing cell with the same ID
        try:
            cell = worksheet.find(self.message_id)
        except gspread.CellNotFound:
            logger.error(f"Failed to edit message with id={self.message_id} - original message not found in sheet.")
            return

        if not cell.col == ColumnHeaders['MessageID'].value:
            logger.error(f"Failed to edit message with id={self.message_id} - no message with same ID found.")
            return

        # Get column value where the message is stored
        message_cell_col = ColumnHeaders['Message'].value
        # Get column value where edited timestamp is stored
        edited_timestamp_cell_col = ColumnHeaders['LastEdited'].value

        # Updated the cells with new edits
        worksheet.update_cell(cell.row, message_cell_col, self.message)
        worksheet.update_cell(cell.row, edited_timestamp_cell_col, self.edit_timestamp.isoformat())

        # Prints success to console
        logger.info(f"Cells ({cell.row}, {message_cell_col}), ({cell.row}, {edited_timestamp_cell_col}) updated")
Ejemplo n.º 2
0
def find_lang_col(sheet: Worksheet, sync=True):
    if sync:
        sync_lang(sheet)
    return {
        lang: sheet.find(lang, in_row=1).col
        for lang in language_pack.languages
    }
Ejemplo n.º 3
0
def remove_keys(sheet: Worksheet, keys: List[str]):
    rows = []
    _remove_keys = []
    col_num = get_id_field_cell(sheet).col
    for k in keys:
        try:
            cell = sheet.find(k, in_column=col_num)
            rows.append(cell.row)
            _remove_keys.append(k)
        except Exception as e:
            pass
    if rows:
        sheet.delete_rows(rows)
        print(f'remove {len(rows)} keys')
        print(_remove_keys)
Ejemplo n.º 4
0
    def apply_to_sheet(self, worksheet: gspread.Worksheet):
        """
        Remove the row corresponding to this update's deleted message from
        the specified Google Sheet worksheet.
        """
        # Find existing cell with the same ID
        try:
            cell = worksheet.find(self.message_id)
        except gspread.CellNotFound:
            logger.error(f"Failed to delete message with id={self.message_id} - original message not found in sheet.")
            return

        if not cell.col == ColumnHeaders['MessageID'].value:
            logger.error(f"Failed to delete message with id={self.message_id} - no message with same ID found.")
            return

        worksheet.delete_row(cell.row)
        # Prints Success message to console
        logger.info(f"Successfully deleted message with id={self.message_id}.")
Ejemplo n.º 5
0
def get_id_field_cell(sheet: Worksheet):
    return sheet.find(ID_FIELD, in_row=1)