implements fresh status retrieval if needed

pull/18/head
msramalho 2022-03-10 19:00:02 +01:00
rodzic 52333874c9
commit 6c5d6f521e
2 zmienionych plików z 9 dodań i 4 usunięć

Wyświetl plik

@ -108,7 +108,8 @@ def process_sheet(sheet, header=1, columns=GWorksheet.COLUMN_NAMES):
# loop through rows in worksheet # loop through rows in worksheet
for row in range(1 + header, gw.count_rows() + 1): for row in range(1 + header, gw.count_rows() + 1):
url = gw.get_cell(row, 'url') url = gw.get_cell(row, 'url')
status = gw.get_cell(row, 'status') original_status = gw.get_cell(row, 'status')
status = gw.get_cell(row, 'status', fresh=original_status in ['', None])
if url != '' and status in ['', None]: if url != '' and status in ['', None]:
gw.set_cell(row, 'status', 'Archive in progress') gw.set_cell(row, 'status', 'Archive in progress')
@ -146,7 +147,7 @@ def process_sheet(sheet, header=1, columns=GWorksheet.COLUMN_NAMES):
def main(): def main():
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Automatically archive social media videos from a Google Sheets document') description='Automatically archive social media videos from a Google Sheets document')
parser.add_argument('--sheet', action='store', dest='sheet') parser.add_argument('--sheet', action='store', dest='sheet', help='the name of the google sheets document', required=True)
parser.add_argument('--header', action='store', dest='header', default=1, type=int, help='1-based index for the header row') parser.add_argument('--header', action='store', dest='header', default=1, type=int, help='1-based index for the header row')
for k, v in GWorksheet.COLUMN_NAMES.items(): for k, v in GWorksheet.COLUMN_NAMES.items():
parser.add_argument(f'--col-{k}', action='store', dest=k, default=v, help=f'the name of the column to fill with {k} (defaults={v})') parser.add_argument(f'--col-{k}', action='store', dest=k, default=v, help=f'the name of the column to fill with {k} (defaults={v})')

Wyświetl plik

@ -44,16 +44,20 @@ class GWorksheet:
def get_values(self): def get_values(self):
return self.values return self.values
def get_cell(self, row, col: str): def get_cell(self, row, col: str, fresh=False):
""" """
returns the cell value from (row, col), returns the cell value from (row, col),
where row can be an index (1-based) OR list of values where row can be an index (1-based) OR list of values
as received from self.get_row(row) as received from self.get_row(row)
if fresh=True, the sheet is queried again for this cell
""" """
col_index = self._col_index(col)
if fresh:
return self.wks.cell(row, col_index + 1).value
if type(row) == int: if type(row) == int:
row = self.get_row(row) row = self.get_row(row)
col_index = self._col_index(col)
if col_index >= len(row): if col_index >= len(row):
return '' return ''
return row[col_index] return row[col_index]