tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
659 stars 421 forks source link

How to get the job_id for a particular workbook #1275

Closed DHANOLA closed 9 months ago

DHANOLA commented 1 year ago

Hi there! I would like to ask how can I able to extract all the job IDs for a particular workbook. I can able to access all the jobs but am unable to figure out how to get only the job IDs of a particular workbook.

import tableauserverclient as TSC
import sys
import os
import pandas as pd
import win32com.client
from PyPDF2 import PdfMerger, PdfWriter, PdfFileReader
from datetime import datetime, time, date
import tempfile
import numpy as np
from notifypy import Notify
import shutil
from datetime import timedelta
import pytz

tableau_auth = TSC.TableauAuth('user', 'password', 'site name')
server = TSC.Server('url', use_server_version=True)
timeout_minutes = 300
server.add_http_options({'timeout': timeout_minutes*60})
conn = server.auth.sign_in(tableau_auth)

for i in server.jobs.all():
    if i.created_at!=None and i.started_at!=None and i.ended_at!=None:
                print(i.type,i.id,
          datetime.strptime(str(i.created_at), "%Y-%m-%d %H:%M:%S%z").astimezone(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S %Z%z"),
          datetime.strptime(str(i.started_at), "%Y-%m-%d %H:%M:%S%z").astimezone(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S %Z%z"),
          datetime.strptime(str(i.ended_at), "%Y-%m-%d %H:%M:%S%z").astimezone(pytz.timezone("Asia/Kolkata")).strftime("%Y-%m-%d %H:%M:%S %Z%z")
          ,i.status)

image

jorwoods commented 1 year ago

Your example code does fetch all workbooks, but you have to query the job by id as well to get the further detail.


# Assuming you have the desired workbook_id in a variable already.
workbook_jobs = []
for job in server.jobs.all():
    job = server.jobs.get_by_id(job.id)
    if job.workbook_id == workbook_id:
        workbook_jobs.append(job)