8000 Jac/export sample fix by jacalata · Pull Request #1034 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Jac/export sample fix #1034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added out.pdf
Binary file not shown.
77 changes: 0 additions & 77 deletions samples/download_view_image.py

This file was deleted.

29 changes: 22 additions & 7 deletions samples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ def main():
group.add_argument(
"--csv", dest="type", action="store_const", const=("populate_csv", "CSVRequestOptions", "csv", "csv")
)
# other options shown in explore_workbooks: workbook.download, workbook.preview_image

parser.add_argument("--workbook", action="store_true")

parser.add_argument("--file", "-f", help="filename to store the exported data")
parser.add_argument("--filter", "-vf", metavar="COLUMN:VALUE", help="View filter to apply to the view")
parser.add_argument("resource_id", help="LUID for the view")
parser.add_argument("resource_id", help="LUID for the view or workbook")

args = parser.parse_args()

Expand All @@ -52,34 +55,46 @@ def main():
logging.basicConfig(level=logging_level)

tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": False})
with server.auth.sign_in(tableau_auth):
views = filter(lambda x: x.id == args.resource_id or x.name == args.resource_id, TSC.Pager(server.views.get))
view = list(views).pop() # in python 3 filter() returns a filter object
print("Connected")
if args.workbook:
item = server.workbooks.get_by_id(args.resource_id)
else:
item = server.views.get_by_id(args.resource_id)

if not item:
print("No item found for id {}".format(args.resource_id))
exit(1)

print("Item found: {}".format(item.name))
# We have a number of different types and functions for each different export type.
# We encode that information above in the const=(...) parameter to the add_argument function to make
# the code automatically adapt for the type of export the user is doing.
# We unroll that information into methods we can call, or objects we can create by using getattr()
(populate_func_name, option_factory_name, member_name, extension) = args.type
populate = getattr(server.views, populate_func_name)
if args.workbook:
populate = getattr(server.workbooks, populate_func_name)

option_factory = getattr(TSC, option_factory_name)

if args.filter:
options = option_factory().vf(*args.filter.split(":"))
else:
options = None

if args.file:
filename = args.file
else:
filename = "out.{}".format(extension)

populate(view, options)
populate(item, options)
with open(filename, "wb") as f:
if member_name == "csv":
f.writelines(getattr(view, member_name))
f.writelines(getattr(item, member_name))
else:
f.write(getattr(view, member_name))
f.write(getattr(item, member_name))
print("saved to " + filename)


Expand Down
101 changes: 0 additions & 101 deletions samples/export_wb.py

This file was deleted.

4 changes: 2 additions & 2 deletions tableauserverclient/server/endpoint/tasks_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def get_by_id(self, task_id):
@api(version="2.6")
def run(self, task_item):
if not task_item.id:
error = "User item missing ID."
error = "Task item missing ID."
raise MissingRequiredFieldError(error)

url = "{0}/{1}/{2}/runNow".format(
Expand All @@ -63,7 +63,7 @@ def run(self, task_item):
)
run_req = RequestFactory.Task.run_req(task_item)
server_response = self.post_request(url, run_req)
return server_response.content
return server_response.content # Todo add typing

# Delete 1 task by id
@api(version="3.6")
Expand Down
0