Skip to content

Instantly share code, notes, and snippets.

View divinorum-webb's full-sized avatar
🐍
python

Elliott divinorum-webb

🐍
python
  • Amsterdam
View GitHub Profile
@divinorum-webb
divinorum-webb / devyx-example-not-using-cte.sql
Created December 5, 2023 20:45
devyx-example-not-using-cte
SELECT
hvc.customer_id
, total_revenue
, days_since_first_seen
FROM (
SELECT
customer_id
, SUM(total_revenue) AS total_revenue
FROM transaction_details td
LEFT JOIN customer_details cd
@divinorum-webb
divinorum-webb / devyx-sql-example-cte.sql
Created December 5, 2023 20:43
devyx-sql-example-cte
WITH high_value_customers AS (
SELECT
customer_id
, SUM(total_revenue) AS total_revenue
FROM transaction_details td
LEFT JOIN customer_details cd
ON td.card_id = cd.card_id
GROUP BY 1
ORDER BY 2 DESC
HAVING total_revenue > 500
@divinorum-webb
divinorum-webb / tableau-api-lib-query-workbook-metadata.py
Created April 24, 2020 23:36
Python code for querying Tableau visuals and their underlying database assets to build impact analysis reports (milestone1)
import pandas as pd
from pandas.io.json import json_normalize
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import flatten_dict_column, flatten_dict_list_column
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
'my_env': {
@divinorum-webb
divinorum-webb / tableau-api-lib-query-metadata-all-sites.py
Last active August 29, 2023 12:42
Template code for querying the Tableau Metadata API for all sites on a server
import pandas as pd
from pandas.io.json import json_normalize
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import flatten_dict_column, flatten_dict_list_column
from tableau_api_lib.utils.querying import get_sites_dataframe
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-query-metadata-all-sites.py
Created May 20, 2020 22:25
Template code for querying the Tableau Metadata API for all sites on a server
import pandas as pd
from pandas.io.json import json_normalize
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import flatten_dict_column, flatten_dict_list_column
from tableau_api_lib.utils.querying import get_sites_dataframe
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-remove-content-owners.py
Created May 29, 2020 20:20
Template code for removing Tableau users who own content using Python and tableau-api-lib
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import querying, flatten_dict_column
# using personal access tokens is preferred; otherwise, comment those details out and use username / password
tableau_server_config = {
'my_env': {
'server': 'https://10ax.online.tableau.com', # replace with your own server
@divinorum-webb
divinorum-webb / tableau-api-lib-download-view-crosstab.py
Last active June 14, 2023 06:16
Template code for downloading view data and pivoting it using Python and tableau-api-lib
import pandas as pd
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.sample import sample_config
from tableau_api_lib.utils import querying
from tableau_api_lib.utils.common import flatten_dict_column
# sample config
tableau_server_config = {
@divinorum-webb
divinorum-webb / tableau-api-lib-trigger-extract-refreshes.py
Created April 15, 2020 23:25
Template code for triggering Tableau Server extract refreshes using Python and tableau-api-lib.
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_workbooks_dataframe, get_datasources_dataframe
TS_CONFIG = {
'my_env': {
'server': 'https://YourTableauServer.com',
'api_version': '<YOUR_API_VERSION>',
'username': '<YOUR_USERNAME>',
'password': '<YOUR_PASSWORD>',
@divinorum-webb
divinorum-webb / create-hyper-extract-from-csv.py
Created April 3, 2020 19:13
Creating a Tableau Hyper extract from a CSV file with Python using the Hyper API
from tableauhyperapi import HyperProcess, Connection, TableDefinition, SqlType, Telemetry, Inserter, CreateMode, TableName
from tableauhyperapi import escape_string_literal
PATH_TO_CSV = 'sample_csv_for_hyper.csv'
PATH_TO_HYPER = 'test_hyper_extract_api.hyper'
# Step 1: Start a new private local Hyper instance
with HyperProcess(Telemetry.SEND_USAGE_DATA_TO_TABLEAU, 'myapp' ) as hyper:
@divinorum-webb
divinorum-webb / tableau-api-lib-publish-workbook.py
Created April 13, 2020 22:58
Template code for publishing workbooks to Tableau Server using tableau-api-lib and Tableau's REST API.
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_projects_dataframe
# Set the following constants according to your environment
YOUR_PROJECT_ID = 'ENTER_YOUR_TS_PROJECT_ID'
YOUR_WORKBOOK_FILE_PATH = 'ENTER_YOUR_WORKBOOK_FILE_PATH'
YOUR_WORKBOOK_NAME = 'ENTER_YOUR_DESIRED_WORKBOOK_NAME'
YOUR_TABLEAU_SERVER_ADDRESS = 'ENTER_YOUR_TABLEAU_SERVER_ADDRESS'
YOUR_DB_SERVER_ADDRESS = 'ENTER_YOUR_DB_SERVER_ADDRESS'