Skip to content

Commit

Permalink
fix types & spell checks
Browse files Browse the repository at this point in the history
  • Loading branch information
ltiffanydev committed Jan 17, 2024
1 parent 0f5349b commit a64b9b4
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 134 deletions.
32 changes: 21 additions & 11 deletions samples/update_workbook_data_acceleration.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
server = TSC.Server(args.server, use_server_version=False)
server.add_http_options({"verify": False})
server.use_server_version()
with (server.auth.sign_in(tableau_auth)):
with server.auth.sign_in(tableau_auth):
# Get workbook
all_workbooks, pagination_item = server.workbooks.get()
print("\nThere are {} workbooks on site: ".format(pagination_item.total_available))
Expand All @@ -56,8 +56,8 @@ def main():

# Enable acceleration for all the views in the workbook
enable_config = dict()
enable_config['acceleration_enabled'] = True
enable_config['accelerate_now'] = True
enable_config["acceleration_enabled"] = True
enable_config["accelerate_now"] = True

sample_workbook.data_acceleration_config = enable_config
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
Expand All @@ -72,27 +72,37 @@ def main():
sample_workbook.views = [view_to_disable]

disable_config = dict()
disable_config['acceleration_enabled'] = False
disable_config['accelerate_now'] = True
disable_config["acceleration_enabled"] = False
disable_config["accelerate_now"] = True

sample_workbook.data_acceleration_config = disable_config
# To get the acceleration status on the response, set includeViewAccelerationStatus=true
# Note that you have to populate_views first to get the acceleration status, since
# acceleration status is per view basis (not per workbook)
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook, True)
view1 = updated.views[0]
print("Disabled acceleration for 1 view " + view1.name + " in the workbook " + updated.name +".")
print("Disabled acceleration for 1 view " + view1.name + " in the workbook " + updated.name + ".")

# Get acceleration status of the views in workbook using workbooks.get_by_id
# This won't need to do populate_views beforehand
my_workbook = server.workbooks.get_by_id(sample_workbook.id)
view1 = my_workbook.views[0]
view2 = my_workbook.views[1]
print("Fetching acceleration status for views in the workbook " + updated.name + ".\n" +
"View \"" + view1.name + "\" has acceleration_status = " +
view1.data_acceleration_config['acceleration_status'] + ".\n" +
"View \"" + view2.name + "\" has acceleration_status = " +
view2.data_acceleration_config['acceleration_status'] + ".")
print(
"Fetching acceleration status for views in the workbook "
+ updated.name
+ ".\n"
+ 'View "'
+ view1.name
+ '" has acceleration_status = '
+ view1.data_acceleration_config["acceleration_status"]
+ ".\n"
+ 'View "'
+ view2.name
+ '" has acceleration_status = '
+ view2.data_acceleration_config["acceleration_status"]
+ "."
)


if __name__ == "__main__":
Expand Down
139 changes: 92 additions & 47 deletions samples/update_workbook_data_freshness_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def main():
server = TSC.Server(args.server, use_server_version=False)
server.add_http_options({"verify": False})
server.use_server_version()
with (server.auth.sign_in(tableau_auth)):
with server.auth.sign_in(tableau_auth):
# Get workbook
all_workbooks, pagination_item = server.workbooks.get()
print("\nThere are {} workbooks on site: ".format(pagination_item.total_available))
Expand All @@ -57,108 +57,153 @@ def main():
# it could mean the workbook selected does not have live connection, which means it doesn't have
# data freshness policy. Change to another workbook with live datasource connection.
sample_workbook_extended = server.workbooks.get_by_id(sample_workbook.id)
print("Workbook " + sample_workbook.name + " has data freshness policy option set to: " +
sample_workbook_extended.data_freshness_policy.option)
print(
"Workbook "
+ sample_workbook.name
+ " has data freshness policy option set to: "
+ sample_workbook_extended.data_freshness_policy.option
)

# Update Workbook Data Freshness Policy to "AlwaysLive"
sample_workbook.data_freshness_policy = TSC.DataFreshnessPolicyItem(
TSC.DataFreshnessPolicyItem.Option.AlwaysLive)
TSC.DataFreshnessPolicyItem.Option.AlwaysLive
)
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option)
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
)

# Update Workbook Data Freshness Policy to "SiteDefault"
sample_workbook.data_freshness_policy = TSC.DataFreshnessPolicyItem(
TSC.DataFreshnessPolicyItem.Option.SiteDefault)
TSC.DataFreshnessPolicyItem.Option.SiteDefault
)
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option)
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
)

# Update Workbook Data Freshness Policy to "FreshEvery" schedule.
# Set the schedule to be fresh every 10 hours
# Once the data_freshness_policy is already populated (e.g. due to previous calls),
# it is possible to directly change the option & other parameters directly like below
sample_workbook.data_freshness_policy.option = TSC.DataFreshnessPolicyItem.Option.FreshEvery
fresh_every_ten_hours = TSC.DataFreshnessPolicyItem.FreshEvery(
TSC.DataFreshnessPolicyItem.FreshEvery.Frequency.Hours,
10
)
TSC.DataFreshnessPolicyItem.FreshEvery.Frequency.Hours, 10
)
sample_workbook.data_freshness_policy.fresh_every_schedule = fresh_every_ten_hours
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option + " with frequency of " +
str(updated.data_freshness_policy.fresh_every_schedule.value) + " " +
updated.data_freshness_policy.fresh_every_schedule.frequency)
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
+ " with frequency of "
+ str(updated.data_freshness_policy.fresh_every_schedule.value)
+ " "
+ updated.data_freshness_policy.fresh_every_schedule.frequency
)

# Update Workbook Data Freshness Policy to "FreshAt" schedule.
# Set the schedule to be fresh at 10AM every day
sample_workbook.data_freshness_policy.option = TSC.DataFreshnessPolicyItem.Option.FreshAt
fresh_at_ten_daily = TSC.DataFreshnessPolicyItem.FreshAt(
TSC.DataFreshnessPolicyItem.FreshAt.Frequency.Day,
"10:00:00",
"America/Los_Angeles"
)
TSC.DataFreshnessPolicyItem.FreshAt.Frequency.Day, "10:00:00", "America/Los_Angeles"
)
sample_workbook.data_freshness_policy.fresh_at_schedule = fresh_at_ten_daily
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option + " with frequency of " +
str(updated.data_freshness_policy.fresh_at_schedule.time) + " every " +
updated.data_freshness_policy.fresh_at_schedule.frequency)
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
+ " with frequency of "
+ str(updated.data_freshness_policy.fresh_at_schedule.time)
+ " every "
+ updated.data_freshness_policy.fresh_at_schedule.frequency
)

# Set the schedule to be fresh at 6PM every week on Wednesday and Sunday
sample_workbook.data_freshness_policy = TSC.DataFreshnessPolicyItem(
TSC.DataFreshnessPolicyItem.Option.FreshAt)
TSC.DataFreshnessPolicyItem.Option.FreshAt
)
fresh_at_6pm_wed_sun = TSC.DataFreshnessPolicyItem.FreshAt(
TSC.DataFreshnessPolicyItem.FreshAt.Frequency.Week,
"18:00:00",
"America/Los_Angeles",
[IntervalItem.Day.Wednesday, "Sunday"]
[IntervalItem.Day.Wednesday, "Sunday"],
)

sample_workbook.data_freshness_policy.fresh_at_schedule = fresh_at_6pm_wed_sun
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
new_fresh_at_schedule = updated.data_freshness_policy.fresh_at_schedule
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option + " with frequency of " +
str(new_fresh_at_schedule.time) + " every " +
new_fresh_at_schedule.frequency + " on " +
new_fresh_at_schedule.interval_item[0] + "," + new_fresh_at_schedule.interval_item[1])
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
+ " with frequency of "
+ str(new_fresh_at_schedule.time)
+ " every "
+ new_fresh_at_schedule.frequency
+ " on "
+ new_fresh_at_schedule.interval_item[0]
+ ","
+ new_fresh_at_schedule.interval_item[1]
)

# Set the schedule to be fresh at 12AM every last day of the month
sample_workbook.data_freshness_policy = TSC.DataFreshnessPolicyItem(
TSC.DataFreshnessPolicyItem.Option.FreshAt)
TSC.DataFreshnessPolicyItem.Option.FreshAt
)
fresh_at_last_day_of_month = TSC.DataFreshnessPolicyItem.FreshAt(
TSC.DataFreshnessPolicyItem.FreshAt.Frequency.Month,
"00:00:00",
"America/Los_Angeles",
["LastDay"]
TSC.DataFreshnessPolicyItem.FreshAt.Frequency.Month, "00:00:00", "America/Los_Angeles", ["LastDay"]
)

sample_workbook.data_freshness_policy.fresh_at_schedule = fresh_at_last_day_of_month
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
new_fresh_at_schedule = updated.data_freshness_policy.fresh_at_schedule
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option + " with frequency of " +
str(new_fresh_at_schedule.time) + " every " +
new_fresh_at_schedule.frequency + " on " +
new_fresh_at_schedule.interval_item[0])
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
+ " with frequency of "
+ str(new_fresh_at_schedule.time)
+ " every "
+ new_fresh_at_schedule.frequency
+ " on "
+ new_fresh_at_schedule.interval_item[0]
)

# Set the schedule to be fresh at 8PM every 1st,13th,20th day of the month
fresh_at_dates_of_month = TSC.DataFreshnessPolicyItem.FreshAt(
TSC.DataFreshnessPolicyItem.FreshAt.Frequency.Month,
"00:00:00",
"America/Los_Angeles",
["1", "13", "20"]
["1", "13", "20"],
)

sample_workbook.data_freshness_policy.fresh_at_schedule = fresh_at_dates_of_month
updated: TSC.WorkbookItem = server.workbooks.update(sample_workbook)
new_fresh_at_schedule = updated.data_freshness_policy.fresh_at_schedule
print("Workbook " + updated.name + " updated data freshness policy option to: " +
updated.data_freshness_policy.option + " with frequency of " +
str(new_fresh_at_schedule.time) + " every " +
new_fresh_at_schedule.frequency + " on " +
str(new_fresh_at_schedule.interval_item))
print(
"Workbook "
+ updated.name
+ " updated data freshness policy option to: "
+ updated.data_freshness_policy.option
+ " with frequency of "
+ str(new_fresh_at_schedule.time)
+ " every "
+ new_fresh_at_schedule.frequency
+ " on "
+ str(new_fresh_at_schedule.interval_item)
)


if __name__ == "__main__":
Expand Down
38 changes: 21 additions & 17 deletions tableauserverclient/models/data_freshness_policy_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class DataFreshnessPolicyItem:

class Option:
AlwaysLive = "AlwaysLive"
SiteDefault = "SiteDefault"
Expand All @@ -25,7 +24,7 @@ def __init__(self, frequency: str, value: int):
self.value: int = value

def __str__(self):
return '<FreshEverySchedule frequency={_frequency} value={_value}>'.format(**vars(self))
return "<FreshEverySchedule frequency={_frequency} value={_value}>".format(**vars(self))

@property
def frequency(self) -> str:
Expand All @@ -38,10 +37,11 @@ def frequency(self, value: str):

@classmethod
def from_xml_element(cls, fresh_every_schedule_elem: ET.Element):
frequency = fresh_every_schedule_elem.get("frequency")
value = fresh_every_schedule_elem.get("value")
if value:
value = int(value)
frequency = fresh_every_schedule_elem.get("frequency", None)
value_str = fresh_every_schedule_elem.get("value", None)
if (frequency is None) or (value_str is None):
return None
value = int(value_str)
return DataFreshnessPolicyItem.FreshEvery(frequency, value)

class FreshAt:
Expand All @@ -57,8 +57,10 @@ def __init__(self, frequency: str, time: str, timezone, interval_item: Optional[
self.interval_item: Optional[List[str]] = interval_item

def __str__(self):
return ('<FreshAtSchedule frequency={_frequency} time={_time}> timezone={_timezone} '
'interval_item={_interval_time}').format(**vars(self))
return (
"<FreshAtSchedule frequency={_frequency} time={_time}> timezone={_timezone} "
"interval_item={_interval_time}"
).format(**vars(self))

@property
def interval_item(self) -> Optional[List[str]]:
Expand Down Expand Up @@ -98,60 +100,62 @@ def frequency(self, value: str):
def from_xml_element(cls, fresh_at_schedule_elem: ET.Element, ns):
frequency = fresh_at_schedule_elem.get("frequency", None)
time = fresh_at_schedule_elem.get("time", None)
if (frequency is None) or (time is None):
return None
timezone = fresh_at_schedule_elem.get("timezone", None)
interval = parse_intervals(fresh_at_schedule_elem, frequency, ns)
return DataFreshnessPolicyItem.FreshAt(frequency, time, timezone, interval)

def __init__(self, option: Option):
def __init__(self, option: str):
self.option = option
self.fresh_every_schedule: Optional[DataFreshnessPolicyItem.FreshEvery] = None
self.fresh_at_schedule: Optional[DataFreshnessPolicyItem.FreshAt] = None

def __str__(self):
return '<DataFreshnessPolicy option={_option}>'.format(**vars(self))
return "<DataFreshnessPolicy option={_option}>".format(**vars(self))

def __repr__(self):
return self.__str__() + " { " + ", ".join(" % s: % s" % item for item in vars(self).items()) + "}"

@property
def option(self) -> Option:
def option(self) -> str:
return self._option

@option.setter
@property_is_enum(Option)
def option(self, value: Option):
def option(self, value: str):
self._option = value

@property
def fresh_every_schedule(self) -> Optional[FreshEvery]:
return self._fresh_every_schedule

@fresh_every_schedule.setter
def fresh_every_schedule(self, value: fresh_every_schedule):
def fresh_every_schedule(self, value: FreshEvery):
self._fresh_every_schedule = value

@property
def fresh_at_schedule(self) -> Optional[FreshAt]:
return self._fresh_at_schedule

@fresh_at_schedule.setter
def fresh_at_schedule(self, value: fresh_at_schedule):
def fresh_at_schedule(self, value: FreshAt):
self._fresh_at_schedule = value

@classmethod
def from_xml_element(cls, data_freshness_policy_elem, ns):

option = data_freshness_policy_elem.get("option", None)
if option is None:
return None
data_freshness_policy = DataFreshnessPolicyItem(option)

fresh_at_schedule = None
fresh_every_schedule = None
if option == 'FreshAt':
if option == "FreshAt":
fresh_at_schedule_elem = data_freshness_policy_elem.find(".//t:freshAtSchedule", namespaces=ns)
fresh_at_schedule = DataFreshnessPolicyItem.FreshAt.from_xml_element(fresh_at_schedule_elem, ns)
data_freshness_policy.fresh_at_schedule = fresh_at_schedule
elif option == 'FreshEvery':
elif option == "FreshEvery":
fresh_every_schedule_elem = data_freshness_policy_elem.find(".//t:freshEverySchedule", namespaces=ns)
fresh_every_schedule = DataFreshnessPolicyItem.FreshEvery.from_xml_element(fresh_every_schedule_elem)
data_freshness_policy.fresh_every_schedule = fresh_every_schedule
Expand Down
Loading

0 comments on commit a64b9b4

Please sign in to comment.