-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdataset_utils.py
More file actions
32 lines (28 loc) · 1.09 KB
/
dataset_utils.py
File metadata and controls
32 lines (28 loc) · 1.09 KB
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
import dataiku
from datetime import datetime
def get_last_build_date(client=None, project_key=None, dataset=None):
"""Returns a datetime onject representing the last time an output
dataset was built.
Args:
client: A handle on the target DSS instance.
project_key: A string representing the target project key.
dataset: name of dataset,
"""
dataset_info = dataiku.Dataset("test_append").get_files_info()
last_modif = dataset_info.get("globalPaths")[0].get("lastModified")
dt = datetime.fromtimestamp(last_modif/1000)
return dt
def build_todays_partition(client=None, project_key=None, dataset=None):
"""Build parition of today's date in specified dataset.
Return status of build.
Args:
client: A handle on the target DSS instance.
project_key: A string representing the target project key.
dataset: name of dataset,
"""
now = datetime.now()
partition = now.strftime("%Y-%m-%d")
project = client.get_project(project_key)
dataset = project.get_dataset(dataset)
job = dataset.build(partitions=partition)
return job.get_status()