-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
60 lines (38 loc) · 1.4 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from pathlib import Path
import sys
from datetime import datetime
import logging
import flywheel
import flywheel_gear_toolkit as gt
from utils import acquire_ROIs as ar
log = logging.getLogger(__name__)
def main(context):
#fw = flywheel.Client()
config = context.config
for inp in context.config_json["inputs"].values():
if inp["base"] == "api-key" and inp["key"]:
api_key = inp["key"]
fw = flywheel.Client(api_key)
# Setup basic logging and log the configuration for this job
if config["gear_log_level"] == "INFO":
context.init_logging("info")
else:
context.init_logging("debug")
context.log_config()
dry_run = config.get('dry-run', False)
log.debug(f"dry_run is {dry_run}")
try:
destination_id = context.destination.get('id')
dest_container = fw.get(destination_id)
project_id = dest_container.parents.project
project = fw.get_project(project_id)
output_dict = ar.acquire_rois(fw, project)
output_path = Path(context.output_dir)/f"{project.label}_ROI-Export_{datetime.now().strftime('%d-%m-%Y_%H-%M-%S')}.csv"
ar.save_csv(output_dict, output_path)
except Exception as e:
log.exception(e)
return 1
return 0
if __name__ == "__main__":
result = main(gt.GearToolkitContext())
sys.exit(result)