4 Replies Latest reply on Oct 10, 2018 1:20 PM by Callum Finlayson

    Programmatically combining a TDE file and a TWB file

    Callum Finlayson

      Hi Community! I am trying to understand the best way to Programmatically combine a TDE file and a TWB file.

       

      I have extracted data (from another REST API), and have formatted it in TDE format (using Python). The format of this data will not change. I have also configured a TWB that has some computed columns and measures etc. I am also running Tableau Server. What I want to do, is when run this application, I create a new TDE file, i upload it to the Tableau server (that bit is working), BUT what I want to do and I am struggling with, is how to update the TWB file with the new data and upload it to the server?

       

      I believe that I am going to likely need to change the format of the TWB file to a TWBX file (ie include the data), but I can't seem to find the information about how I can take my TDE + TWB file and save it as a TWBX file (then upload it to Tableau Server).

       

      I imagine this is pretty simple, but just can't seem to find concise documentation on how I would do this using Python or the REST API.

       

      Cheers,

       

      Callum

        • 1. Re: Programmatically combining a TDE file and a TWB file
          Michael Gillespie

          Callum, I'm not following what you're trying to do.

           

          If you publish an extract data source to Server, and there is a workbook (twb) that points at that data source, it will get the new data without you needing to republish the workbook.  You will have to hit the "Refresh" button in the workbook (whether it's a local twb file that uses a server-based data source OR a published workbook that resides on the same server as the data source).

           

          Why do you think you need to publish a TWBX to Server?

          • 2. Re: Programmatically combining a TDE file and a TWB file
            Callum Finlayson

            Hey Michael, thanks for the reply, and you're correct, the Tableau server part of this thread is a red herring.

             

            What I want to do is much simpler. I have a TDE file and a TWB file, now I want to combine them to create a TWBX file (that I can distribute to others). I can't find an appropriate API call to do this (but I am almost certain one must exist). For now, I am going to write some code to take the two files, Zip them into a file with the structure:

            workbook_name.twb

            <Data> (Folder)

            -- tableau_data_extract.tde

             

            Then rename the zip file extension to TWBX

             

            I am sure this will work, but just thought there must be a more elegant way to do it via an API.

            • 3. Re: Programmatically combining a TDE file and a TWB file
              Michael Gillespie

              I'm not entirely sure that WILL work, but it's worth trying!

               

              Are the folks you intend to send this to as a TWBX file only using Reader?  That is, they don't have access to Server?

               

              Before you go a whole lot further, please look at this thread, particularly the license restrictions on what you're trying to do.

               

              Can you automate the exporting of a packaged workbook?

              • 4. Re: Programmatically combining a TDE file and a TWB file
                Callum Finlayson

                Michael, thanks for the comments.

                 

                I have a working solution in python, that does what I describe, just thought there must be an easier way to do it, but now understand that Tableau don't want you doing this... It seems you're right, as in, it's not allowed from a licensing point of view, so I guess I will never be able to use this code. I will post it here in the hopes that no one else uses it either.

                 

                def create_twbx_from_tde_and_twb(tableau_twbx_file, tableau_tde_file, tableau_twb_template_file, tableau_image_file):
                    #start afresh each run (remove the directory if it exists)
                    temp_dir = "/tmp"
                    if os.path.exists(temp_dir+'/Data'):
                        rmtree(temp_dir+'/Data')
                    if os.path.exists(temp_dir+'/Image'):
                        rmtree(temp_dir+'/Image')
                
                
                    #set/make/copy the files to the directories "Data" and "Image"
                    tde_location = '/Data'
                    twb_image_location = '/Image'
                    os.mkdir(temp_dir+tde_location)
                    os.mkdir(temp_dir+twb_image_location)
                    copyfile(tableau_twb_template_file,temp_dir+'/'+tableau_twb_template_file)
                    copyfile(tableau_tde_file,temp_dir+tde_location+'/'+tableau_tde_file)
                    copyfile(tableau_image_file,temp_dir+twb_image_location+'/'+tableau_image_file)
                
                
                    #zip the 3 files to create the TWBX file (TWB, TDE and a logo image file)
                    z = zipfile.ZipFile(temp_dir+"/"+tableau_twbx_file, "w")
                    z.write(temp_dir+"/"+tableau_twb_template_file,arcname="/"+tableau_twb_template_file)
                    z.write(temp_dir+"/"+tde_location+'/'+tableau_tde_file, arcname=tde_location+'/'+tableau_tde_file)
                    z.write(temp_dir+"/"+twb_image_location+'/'+tableau_image_file, arcname= twb_image_location+'/'+tableau_image_file)
                    z.close()
                

                .