I am looking for a way to download a view of tableau using python. I'm able to login into tableau online via python and able to see listed workbooks and views.
as user doesn't have permission of workbook so can't able to download a workbook, but view I'm able to just entering in chrome but can't able to find a way using python. also i want to save the view in pandas dataframe.
if there is anyway to do the above, kindly let me know?
# coding=utf-8
import tableauserverclient as TSC
import argparse
import requests
import pandas as pd
import csv
parser = argparse.ArgumentParser()
args = parser.parse_args()
tableau_auth = TSC.TableauAuth('admin', 'admin', site_id='test')
server = TSC.Server('https://10az.online.tableau.com')
server.auth.sign_in(tableau_auth)
# print(server.projects.get())
with server.auth.sign_in(tableau_auth):
all_workbooks, pagination_item = server.workbooks.get()
print("\nThere are {} workbooks on site: ".format(pagination_item.total_available))
print([workbook.name for workbook in all_workbooks])
if all_workbooks:
sample_workbook = all_workbooks[3]
server.workbooks.populate_views(sample_workbook)
print("\nName of views in {}: ".format(sample_workbook.name))
print([view.name for view in sample_workbook.views])
print([view.id for view in sample_workbook.views])
server.workbooks.populate_connections(sample_workbook)
print("\nConnections for {}: ".format(sample_workbook.name))
print(["{0}({1})".format(connection.id, connection.datasource_name)
for connection in sample_workbook.connections])
view_id = 'ddd'
server_url = 'https://10az.online.tableau.com'
src_url = "https://10az.online.tableau.com/#/site/abc/views/test/AccountAdvertisersList.csv" \
.format(server_url, server.version, server.site_id, view_id)
# path = server.workbooks.download(sample_workbook.id)
Related
I am using simple_salesforce package in python to be able to get a report from my salesforce account. I am able to login to salesforce successfully with simple_salesforce. However, when I try to download the report (code runs with no errors), I do not get the expected output. Sample code is:
from simple_salesforce import Salesforce
import requests
import pandas as pd
from io import StringIO
sf = Salesforce(username='myusername',
password='mypassword',
security_token='mytoken',
version='46.0')
sf_instance = 'https://companyname.lightning.force.com/' #Your Salesforce Instance URL
reportId = 'myreportid' # add report id
export = '?isdtp=p1&export=1&enc=UTF-8&xf=csv'
sfUrl = sf_instance + reportId + export
response = requests.get(sfUrl, headers=sf.headers, cookies={'sid': sf.session_id})
download_report = response.content.decode('utf-8')
df1 = pd.read_csv(StringIO(download_report))
Output for df1 is not the expected report:
df1.head()
output
Is there anything wrong with the code? I am open to suggestions on another strategy to download the report.
First I want list of sites then next I want list of projects inside each site and then I want list of workbook in each project.
i.e sites>>projects>>workbooks.
I am using Tableauserverclient. Please help me, thanks in advance.
Check out Tableau's github page. It has all the examples.
I would consider using Tableau's workgroup database though unless you are requiring python for some other action.
Sites
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('https://SERVER')
# query the sites
all_sites, pagination_item = server.sites.get()
# print all the site names and ids
for site in all_sites:
print(site.id, site.name, site.content_url, site.state)
Projects
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD', site_id='CONTENTURL')
server = TSC.Server('https://SERVER')
with server.auth.sign_in(tableau_auth):
# get all projects on site
all_project_items, pagination_item = server.projects.get()
print([proj.name for proj in all_project_items])
Workbooks
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('username', 'password', site_id='site')
server = TSC.Server('https://servername')
with server.auth.sign_in(tableau_auth):
all_workbooks_items, pagination_item = server.workbooks.get()
# print names of first 100 workbooks
print([workbook.name for workbook in all_workbooks_items])
I am creating a Python script for downloading a report from Salesforce as a CSV.
My script is working perfectly fine for Salesforce Classic. However, I need to get it working for Lightning Experience. I'm using the simple-salesforce Python package to access our org. For SF Classic I enter a link that is structured like this: https://my-company.my.salesforce.com/my_report_id?view=d&snip&export=1&enc=UTF-8&xf=csv
The script is basically like this:
from simple-salesforce import Salesforce
import requests
import pandas as pd
import csv
from io import StringIO
sf = Salesforce(username="my_username", password="my_password",
security_token="my_token")
sf_org = "https://my_company.my.salesforce.com/"
report_id = "0000" # Some report id
sf_report_loc = "{0}{1}?view=d&snip&export=1&enc=UTF-8&xf=csv".format(sf_org, report_id)
response = requests.get(sf_report_loc, headers=sf.headers, cookies={"sid": sf.session_id})
new_report = response.content.decode("utf-8")
df = pd.read_csv(StringIO(new_report)) # Save the report to a DataFrame.
Whenever I switch to Lightning, the link is invalid and I get redirected. Is there a way to make this work in Lightning?
Try with isdtp parameter. In classic it was used to force view pages without sidebar or header, for example add isdtp=vw to a random page and see what happens.
https://my_company.my.salesforce.com/00O.....?isdtp=p1&export=1&enc=UTF-8&xf=csv ?
(no idea what's 'p1' but that's what I see in Chrome's download history as part of the report's source URL)
I created a python script to save some data to a test database in firebase.
Here's my code:
from firebase import firebase
firebase = firebase.FirebaseApplication('https://www.somefirebaseapp.firebaseapp.com')
result = firebase.post('/data','test_data':'test123')
print(result)
It successfully inserted the data in the firebase console. Now I want to do this by running the python script via terminal (I'm using RPi), and add some arguments to save.
E.G
python3 firebase-save.py thisisatestdata
Which will make the code look like this:
result = firebase.post('/data','test_data':'inserted_argument_here')
How do I achieve this?
You can do this using click (or build in argparse) library
from firebase import firebase
import click
import ast
firebase = firebase.FirebaseApplication('https://www.somefirebaseapp.firebaseapp.com')
#click.command()
#click.option('--data', default='', help='Test data.')
def test(data):
try:
test_data= ast.literal_eval(data)
except ValueError:
pass
result = firebase.post('/data','test_data': test_data)
print(result)
import sys
from firebase import firebase
firebase = firebase.FirebaseApplication('https://www.somefirebaseapp.firebaseapp.com')
param_1= sys.argv[1]
result = firebase.post('/data','test_data':param_1)
print(result)
I'm trying to figure out how to get the Title attribute from the youtube.data object after logging with the youtube.service object. The dblist.dbselectlist() outputs videoids to be concatenated with the uri. any help is appreciated.
here is the code i have so far.
import gdata.youtube
import gdata.youtube.service
import gdata.youtube.data
import dblist
# Create a client class which will make HTTP requests with Google Docs server.
client = gdata.youtube.service.YouTubeService()
# Authenticate using your Google Docs email address and password.
client.email = 'email#outlook.com'
client.password = 'pwdvalue'
client.source = 'my-list-application'
client.developer_key = 'xxxxx'
client.client_id = 'my-list-application'
client.ProgrammaticLogin()
#select all videoids in the rotatevids table
listrotate = dblist.dbselectrotatelist()
for row in listrotate:
videoid= row["videoid"]
uri = 'https://gdata.youtube.com/feeds/api/videos/%s?v=2' % (videoid)
print uri
video_feed = client.GetYouTubeVideoFeed(uri)
when I dir(gdata.youtube.data.VideoEntry)
it looks like it has the title and text values i'm looking for hopefully
thanks in advance
video_entry = client.GetYouTubeVideoEntry(video_id=VIDEO_ID)
title = video_entry.title.text
btw I think ProgrammaticLogin is deprecated (https://developers.google.com/youtube/2.0/developers_guide_protocol_clientlogin) , you don't need to login anyway, it just needs the developer key.