kopia lustrzana https://github.com/bellingcat/auto-archiver
gsheet accepts ID too
rodzic
d645b840ee
commit
a655b3c987
|
@ -21,7 +21,7 @@ class Step(ABC):
|
||||||
|
|
||||||
def init(name: str, config: dict, child: Type[Step]) -> Step:
|
def init(name: str, config: dict, child: Type[Step]) -> Step:
|
||||||
"""
|
"""
|
||||||
looks into direct subclasses of child for name and returns such ab object
|
looks into direct subclasses of child for name and returns such an object
|
||||||
TODO: cannot find subclasses of child.subclasses
|
TODO: cannot find subclasses of child.subclasses
|
||||||
"""
|
"""
|
||||||
for sub in child.__subclasses__():
|
for sub in child.__subclasses__():
|
||||||
|
|
|
@ -39,7 +39,7 @@ class GsheetsFeeder(Gsheets, Feeder):
|
||||||
})
|
})
|
||||||
|
|
||||||
def __iter__(self) -> Metadata:
|
def __iter__(self) -> Metadata:
|
||||||
sh = self.gsheets_client.open(self.sheet)
|
sh = self.open_sheet()
|
||||||
for ii, wks in enumerate(sh.worksheets()):
|
for ii, wks in enumerate(sh.worksheets()):
|
||||||
if not self.should_process_sheet(wks.title):
|
if not self.should_process_sheet(wks.title):
|
||||||
logger.debug(f"SKIPPED worksheet '{wks.title}' due to allow/block rules")
|
logger.debug(f"SKIPPED worksheet '{wks.title}' due to allow/block rules")
|
||||||
|
|
|
@ -14,12 +14,13 @@ class Gsheets(Step):
|
||||||
try: self.header = int(self.header)
|
try: self.header = int(self.header)
|
||||||
except: pass
|
except: pass
|
||||||
assert type(self.header) == int, f"header ({self.header}) value must be an integer not {type(self.header)}"
|
assert type(self.header) == int, f"header ({self.header}) value must be an integer not {type(self.header)}"
|
||||||
assert self.sheet is not None, "You need to define a sheet name in your orchestration file when using gsheets."
|
assert self.sheet is not None or self.sheet_id is not None, "You need to define either a 'sheet' name or a 'sheet_id' in your orchestration file when using gsheets."
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def configs() -> dict:
|
def configs() -> dict:
|
||||||
return {
|
return {
|
||||||
"sheet": {"default": None, "help": "name of the sheet to archive"},
|
"sheet": {"default": None, "help": "name of the sheet to archive"},
|
||||||
|
"sheet_id": {"default": None, "help": "(alternative to sheet name) the id of the sheet to archive"},
|
||||||
"header": {"default": 1, "help": "index of the header row (starts at 1)"},
|
"header": {"default": 1, "help": "index of the header row (starts at 1)"},
|
||||||
"service_account": {"default": "secrets/service_account.json", "help": "service account JSON file path"},
|
"service_account": {"default": "secrets/service_account.json", "help": "service account JSON file path"},
|
||||||
"columns": {
|
"columns": {
|
||||||
|
@ -42,3 +43,9 @@ class Gsheets(Step):
|
||||||
"cli_set": lambda cli_val, cur_val: dict(cur_val, **json.loads(cli_val))
|
"cli_set": lambda cli_val, cur_val: dict(cur_val, **json.loads(cli_val))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def open_sheet(self):
|
||||||
|
if self.sheet:
|
||||||
|
return self.gsheets_client.open(self.sheet)
|
||||||
|
else: # self.sheet_id
|
||||||
|
return self.gsheets_client.open_by_key(self.sheet_id)
|
||||||
|
|
Ładowanie…
Reference in New Issue