Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
KristianBubalo authored Jan 7, 2022
1 parent 9248e66 commit b583d65
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@
"source": [
"#Set parameters\r\n",
"\r\n",
"client_id = \"bcf8082e-1493-4488-9f90-de22000007a9\" #Add your Client ID here\r\n",
"client_secret = \"BR0dH_dD693XBX5631_24_t-_KRutM0Avc\" #Add your Client Secret here\r\n",
"tenant_name = \"kbubalo.com\" #Add your tenant name here\r\n",
"workspace_id = \"80945c34-5d3f-4998-b561-8f662a6fee46\" #Add your Workspace ID here\r\n",
"dataset_id = \"b428a792-e384-4fbe-bcba-183492d4912b\" #Add your Dataset ID here\r\n",
"client_id = \"\" #Add your Client ID here\r\n",
"client_secret = \"\" #Add your Client Secret here\r\n",
"tenant_name = \"\" #Add your tenant name here\r\n",
"workspace_id = \"\" #Add your Workspace ID here\r\n",
"dataset_id = \"\" #Add your Dataset ID here\r\n",
"\r\n",
"authority_url = \"https://login.microsoftonline.com/\" + tenant_name \r\n",
"scope = [\"https://analysis.windows.net/powerbi/api/.default\"]\r\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,65 @@
#!/usr/bin/env python
# coding: utf-8

# In[ ]:
# In[28]:


#Import necessary libraries

import msal
import requests
import json
import pandas as pd


# In[29]:


#Set parameters

client_id = "" #Add your Client ID here
client_secret = "" #Add your Client Secret here
tenant_name = "" #Add your tenant name here
workspace_id = "" #Add your Workspace ID here
dataset_id = "" #Add your Dataset ID here

authority_url = "https://login.microsoftonline.com/" + tenant_name
scope = ["https://analysis.windows.net/powerbi/api/.default"]
url = "https://api.powerbi.com/v1.0/myorg/groups/" + workspace_id +"/datasets/"+ dataset_id +"/refreshes?$top=1"


# In[30]:


#Use MSAL to grab token

app = msal.ConfidentialClientApplication(client_id, authority=authority_url, client_credential=client_secret)
result = app.acquire_token_for_client(scopes=scope)

#Get latest Power BI Dataset Refresh
if 'access_token' in result:
access_token = result['access_token']
header = {'Content-Type':'application/json', 'Authorization':f'Bearer {access_token}'}
api_call = requests.get(url=url, headers=header)

result = api_call.json()['value']

df = pd.DataFrame(result, columns=['requestId', 'id', 'refreshType', 'startTime', 'endTime', 'status'])
df.set_index('id')


# In[31]:


if df.status[0] == "Unknown":
print("Dataset is refreshing right now. Please wait until this refresh has finished to trigger a new one.")
elif df.status[0] == "Disabled":
print("Dataset refresh is disabled. Please enable it.")
elif df.status[0] == "Failed":
print("Last Dataset refresh failed. Please check error message.")
elif df.status[0] == "Completed":
api_call = requests.post(url=url, headers=header)
print("We triggered a Dataset refresh.")
else:
print("Not familiar with status, please check documentatino for status: '" + df.status[0] + "'")

0 comments on commit b583d65

Please sign in to comment.