Download tableau files from tableau server in a specific Project name folder on your local machine - tableau-api

I am trying to download all the Tableau files from the server on to my local machine .
The below code is downloading the files from a specific folder onto my C://Users/account/
However I want it should create something like below
1.Iterate through all the project names(Tableau server)
2. create a folder on C://Users/Account using the tableau server Project names.
3.Download all the .twb /.twbx files into the respective projects
# First
import tableauserverclient as TSC
import getpass
import os
# Second
user_login = os.getenv('USERNAME')
pw = getpass.getpass('Please enter the password to login to the tableau server\nPassword: ')
# Third
site = 'Global-IT'
server_name = 'http://metrics-it.corp.amazon.com/'
server = TSC.Server(server_name)
server.version = '3.9'
with server.auth.sign_in(TSC.TableauAuth(username=user_login, password=pw, site=site)):
for wb in [w for w in TSC.Pager(server.workbooks)
if w.project_name.startswith('Temporary - To be Decommisioned',)]:
file_path = server.workbooks.download(wb.id)
print(wb.name, ': ', wb.project_name)
print("Successfully downloaded workbook with workbook id: " + wb.id)
print("\nDownloaded the file to {0}.".format(file_path))
print()
print('-------------------------')
print()
Can someone help me with the code.

Related

ModuleNotFoundError: No module named 'gspread' on python anywhere

What I am trying to achieve.
Run a python script saved On pythonanywhere host from google sheets on a button press.
Check the answer by Dustin Michels
Task of Each File?
app.py: contains code of REST API made using Flask.
runMe.py: contains code for that get values from(google sheet cell A1:A2). And sum both values send sum back to A3.
main.py: contains code for a GET request with an argument as name(runMe.py).filename may change if the user wants to run another file.
I Made an API by using Flask.it works online and offline perfectly but still, if you want to recommend anything related to the app.py.Code Review App.py
from flask import Flask, jsonify
from flask_restful import Api, Resource
import os
app = Flask(__name__)
api = Api(app)
class callApi(Resource):
def get(self, file_name):
my_dir = os.path.dirname(__file__)
file_path = os.path.join(my_dir, file_name)
file = open(file_path)
getvalues = {}
exec(file.read(), getvalues)
return jsonify({'data': getvalues['total']})
api.add_resource(callApi, "/callApi/<string:file_name>")
if __name__ == '__main__':
app.run()
Here is the Code of runMe2.py
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# use creds to create a client to interact with the Google Drive API
scopes =['https://www.googleapis.com/auth/spreadsheets',"https://www.googleapis.com/auth/drive.file","https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name('service_account.json', scopes)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Demosheet").sheet1
# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)
below is the main.py code
import requests
BASE = 'https://username.pythonanywhere.com/callApi/test.py'
response = requests.get(BASE)
print(response.json())
main.py output
{'data': 54}
Test.py code
a = 20
b = 34
total = a+b
print(total)
PROBLEM IS
if I request runMe2.py at that time I am got this error.
check runMe2.py code above
app.py is hosted on https://www.pythonanywhere.com/
ModuleNotFoundError: No module named 'gspread'
However, I installed gspread on pythonanywhere why using the command. but it's not working.
You either haven't installed the gspread package on your current python environment or it is installed somewhere (e.g. in a diff. virtual env) and your script cant find it.
Try installing the package inside the environment your running your script in using pip3:
pip3 install gspread
You can try something like this on Windows
pip install gspread
or on Mac
pip3 install gspread
If you're running on Docker, or building with a requirements.txt you can try adding this line you your requirements.txt file
gspread==3.7.0
Any other instructions for this package can be found here => https://github.com/burnash/gspread
Download gspread here
Download the tar file: gspread-3.7.0.tar.gz from the above link
Extract file and convert folder in zip then upload it back on server
Open bash console and use command as
$ unzip gspread-3.7.0
$ cd gspread-3.7.0
$ python3.7 setup.py install --user

Cannot open connection, deploying Shiny app, tesseract trainingdata for other languages

I've been struggling to deploy my shiny app using the tesseractpackage. It seems that it can't 'reach' the downloaded languages. In my case: English and Dutch.
When setting up the language, the resulting object should 'point' to a path. That's the part where shiny can't open the connection.
Any help would be much appriciated!
Kind regards, R
Below I've copied the error message and the relevant code.
This is the error message I get after deployment:
Warning in file(con, "wb") :
cannot open file '/usr/share/tesseract-ocr/tessdata/nld.traineddata': Permission denied
Error in value[3L] : cannot open the connection
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne ->
Execution halted
This is my code
#loading software requirement
library(tesseract)
#download language (dutch)
tesseract_download('nld')
tesseract_download('eng')
#set language parameters for later use.
dutch <- tesseract('nld')
english <- tesseract('eng')
I've managed to get it working myself. The key was taking the following steps:
Creating a subdirectory (of folder) which is called 'tessdata'. This subdirecty is the directory you can download the languages in and 'set' the languages.
When deploying your app, you have to deploy this tessdata-subdirectory as well. So in the deployement prompt, you 'tick' the boxes of this folder as well.
Then make sure the tesseract engine points at the following path:
Screenshot of how to upload the tessdata-folder along with the app
enter image description here
Please see the code below
#loading software requirementlibrary(tesseract)
#Make sure the tesseract package is 'pointing' at the right 'parent directory'
#which is in this case the path your shiny app is working from.
#That's why you need the dot ("."). Which is in essence the workdir.
Sys.setenv(TESSDAT_PREFIX = ".")
#so combining the workdir and the pre-installed folder 'tessdata'
path <- paste0(getwd(), '/tessdata')
#use this path for downloading
#download languages (dutch and english)
tesseract_download('nld', datapath = path)
tesseract_download('eng', datapath = path)
#set language parameters for later use, using the same path
dutch <- tesseract('nld', datapath = path)
english <- tesseract('eng', datapath = path)

How can I download a file using the WebHDFS knox groovy library?

The WebHDFS examples shows how to list files and folders in hdfs, make a directory and upload a file using BigInsights WebHDFS?
How can I adapt the examples to download a file for BigInsights WebHDFS?
The knox api documentation provides many more examples, e.g.
import groovy.json.JsonSlurper
import org.apache.hadoop.gateway.shell.Hadoop
import org.apache.hadoop.gateway.shell.hdfs.Hdfs
gateway = "https://localhost:8443/gateway/sample"
username = "bob"
password = "bob-password"
dataFile = "README"
session = Hadoop.login( gateway, username, password )
text = Hdfs.get( session ).from( "/tmp/example/README" ).now().string
file = new File('README')
file << text
session.shutdown()

How can we read a config file stored at a location relative to the Mirth Connect Installation directory?

How can we read a config file stored at a location relative to the Mirth Connect Installation directory?
For example if Mirth is installed in /opt/Mirth-Connect directory and I want to read a file from /opt/Mirth-Connect/conf directory without specifying the fully qualified path name.
We are using multiple instances of Mirth for different environments which are installed on the same machine, So I can't hard code full path in channel configurations.
You can read a config file stored at a location relative to the Mirth Connect Installation directory basically in the same way as you would read any other file, i.e.:
var folder = new java.io.File("./conf");
var listOfFiles = folder.listFiles();
for (var i = 0; i < listOfFiles.length; i++) {
if (listOfFiles[i].isFile()) {
// Do what you need with the file - listOfFiles[i].getName());
}
}
The first line gives you a path relative to the mcserver.exe (in Windows env) installation.
Accordingly, folder = File(".") is a Mirth root folder.

Crystal report export to excel : unable to read file

I am using vb6 program to export a crystal report to excel sheet.After running the program the exported excel sheet is unreadable. getting the error "Unable to read file"
CrxRep.DiscardSavedData
CrxRep.ExportOptions.DestinationType = crEDTDiskFile
CrxRep.ExportOptions.FormatType = crEFTExcel97
'Input parameter set
CrxRep.ExportOptions.DiskFileName = DestName
CrxRep.ExportOptions.ExcelExportAllPages = True
CrxRep.EnableParameterPrompting = False
CrxRep.ExportOptions.ExcelUseWorksheetFunctions = True
CrxRep.ExportOptions.ExcelUseTabularFormat = True
CrxRep.ExportOptions.ExcelPageBreaks = True
CrxRep.ExportOptions.ExcelTabHasColumnHeadings = True
CrxRep.Export False
However this problem occurs only on production server.When I tried to export in dev server it works fine.
From where are you trying to read the file ?
If you are logged onto the server and can't read it, that suggests that Excel or perhaps ADO is not installed on the server, but you can answer that by looking at the icon. If windows recognizes the file type and shows you the Excel icon, then Excel is installed there.
If Excel is installed there, then copy the file to your desktop, or to the dev server, and try to open it there. If it opens there...the problem is likely a missing component ( perhaps ADO ) on the prod server.